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

Add support for non-consuming projections of union payloads #1568

Merged
merged 5 commits into from
Aug 23, 2024

Conversation

kyouko-taiga
Copy link
Contributor

The following program is now legal:

fun f(_ x: Optional<Int>) {
  if let y: Int = x { print(y) }
}

Previously, the compiler would complain that x can't be consumed because all narrowing conversions required a sink access on the source.

The previous design of the instruction did not require the operand
to be the result of a 'let' access, which would cause problems
during access reification. The new design consumes a discriminator
value that must have been obtained from 'union_discriminator'.

An alternative design could be to require that the first operand be
an access that would be passed as a basic block arguments to the
different targets. This approach makes it more difficult to track
lifetime dependencies, though.
@kyouko-taiga
Copy link
Contributor Author

This PR implements #1099.

Copy link

codecov bot commented Aug 23, 2024

Codecov Report

Attention: Patch coverage is 95.55556% with 4 lines in your changes missing coverage. Please review.

Project coverage is 87.83%. Comparing base (d61d644) to head (dff9eca).
Report is 6 commits behind head on main.

Files Patch % Lines
Sources/IR/Emitter.swift 97.10% 2 Missing ⚠️
Sources/IR/Operands/Instruction/UnionSwitch.swift 80.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1568      +/-   ##
==========================================
+ Coverage   87.76%   87.83%   +0.06%     
==========================================
  Files         373      373              
  Lines       22621    22627       +6     
==========================================
+ Hits        19854    19875      +21     
+ Misses       2767     2752      -15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kyouko-taiga kyouko-taiga merged commit 610865d into main Aug 23, 2024
16 checks passed
@kyouko-taiga kyouko-taiga deleted the non-consuming-narrowing branch August 23, 2024 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant