Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: incorrect code generation for parameter borrowing #1460

Merged

Conversation

zerbina
Copy link
Collaborator

@zerbina zerbina commented Sep 11, 2024

Summary

Fix parameters below the pass-by-reference size threshold not being
passed by reference when the procedure returns a non-direct view,
resulting in access violations at run-time when trying to access the
returned view.

Details

  • consider immutable non-direct views (e.g., object types with lent
    fields) when deciding whether pass-by-reference is used for the first
    parameter of a procedure
  • move the classifyViewType procedures from typeallowed to types,
    as they're wholly unrelated to the "type allowed" checks

Fixes #1457.

Querying whether and what kind of view a type represents has nothing to
do with the "type allowed" checks.
Both `mirgen` and `isPassByRef` didn't consider non-direct views when
deciding whether the parameter uses pass-by-reference. Now they do.
@zerbina zerbina added bug Something isn't working compiler/backend Related to backend system of the compiler labels Sep 11, 2024
@zerbina zerbina added this to the MIR phase milestone Sep 11, 2024
Copy link
Collaborator

@saem saem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor comment related suggestion, but not a blocker.

result = classifyViewTypeAux(marker, t)

proc directViewType*(t: PType): ViewTypeKind =
# does classify 't' without looking recursively into 't'.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# does classify 't' without looking recursively into 't'.
## classifies 't' without looking recursively into 't'.

A tad clearer and shorter, also made it a doc comment as it's relevant to what to expect from the procedure.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but I figured to not modify the moved-over code, so as to allow git tooling to better detect the moved code.

@saem
Copy link
Collaborator

saem commented Sep 11, 2024

/merge

Copy link

Merge requested by: @saem

Contents after the first section break of the PR description has been removed and preserved below:


@chore-runner chore-runner bot added this pull request to the merge queue Sep 11, 2024
Merged via the queue into nim-works:devel with commit 3f92bba Sep 11, 2024
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler/backend Related to backend system of the compiler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

borrows of parameters below byref threshold ends up leasing the copied parameter
2 participants