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

[Typecheck] Failing to compile inlinable function with enable-library-evolution #62507

Closed
LucianoPAlmeida opened this issue Dec 11, 2022 · 3 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself @inlinable Feature → attributes: the @inlinable attribute library evolution Feature: library evolution (umbrella feature for features that facilitate resilient libraries) not a bug Resolution → not a bug: Reported as a bug but turned out to be expected behavior or programmer error type checker Area → compiler: Semantic analysis

Comments

@LucianoPAlmeida
Copy link
Contributor

Description
For the following test case we fail to compile and get 'let' property 'i' may not be initialized directly; use "self.init(...)" or "self = ..." instead only in inlinable init and with enable-library-evolution mode. Not sure why it shouldn't compile

// RUN: %target-typecheck-verify-swift -enable-library-evolution -debug-constraints

public struct A {
  public let i: Int
  
  @inlinable
  public init() {
    self.i = 0
  }
}

The problem seems to be with the bindings for member that for some reason with library evolution enabled find a r-value for member type, causing the failure:

  (overload set choice binding $T0 := @lvalue A)
  (overload set choice binding $T1 := Int)

Without it thing seems to be fine

  (overload set choice binding $T0 := @lvalue A)
  (overload set choice binding $T1 := @lvalue Int)

Where $T0 is the base and $T1 member type.

Steps to reproduce
Run test case above with lit

Expected behavior
This code should compile, I don't see why it would behave differently with enable-library-evolution

Environment

  • Swift compiler version info main @45cd83d73e00230725849603d143ece95bc74467
@LucianoPAlmeida LucianoPAlmeida added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself type checker Area → compiler: Semantic analysis library evolution Feature: library evolution (umbrella feature for features that facilitate resilient libraries) labels Dec 11, 2022
@LucianoPAlmeida LucianoPAlmeida self-assigned this Dec 11, 2022
@LucianoPAlmeida
Copy link
Contributor Author

@xedin This seems to be here since 5.1. Is that by design?
I'm just starting to look into it and go through the code to have more context, but with my current understanding this looks like a bug.

@AnthonyLatsis
Copy link
Collaborator

AnthonyLatsis commented Dec 11, 2022

This feels intentional in the sense that it is not safe to have an inlinable public initializer that initializes storage directly in a non-@frozen struct, namely, the library author might add a new property in a future release and cause memory corruption in clients that already inlined the init.

@AnthonyLatsis AnthonyLatsis added the @inlinable Feature → attributes: the @inlinable attribute label Dec 11, 2022
@LucianoPAlmeida
Copy link
Contributor Author

This feels intentional in the sense that it is not safe to have an inlinable public initializer that initializes storage directly in a non-@frozen struct, namely, the library author might add a new property in a future release and cause memory corruption in clients that already inlined the init.

Yeah, that makes sense.
Just found debugging the code that this is indeed an intentional rule.
Closing this then, thank you for the input @AnthonyLatsis!

Ah just for context this comes from this issue apple/swift-algorithms#189

@AnthonyLatsis AnthonyLatsis added the not a bug Resolution → not a bug: Reported as a bug but turned out to be expected behavior or programmer error label Dec 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself @inlinable Feature → attributes: the @inlinable attribute library evolution Feature: library evolution (umbrella feature for features that facilitate resilient libraries) not a bug Resolution → not a bug: Reported as a bug but turned out to be expected behavior or programmer error type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants