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

[AutoDiff] Fix assert on missing struct decl on cross-file derivative search #77183

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kovdan01
Copy link

Consider:

  1. File struct.swift defining struct Struct with static func max member
  2. File derivatives.swift defining extension Struct with custom derivative of the max function
  3. File error.swift defining a differentiable function which uses Struct.max.

Previously, when passing error.swift as primary file and derivatives.swift as a secondary file to swift-frontend (and forgetting to pass struct.swift as a secondary file as well), an assertion failure was triggered in the following call stack:

assert(type->mayHaveMembers()); // while type is ErrorType
TypeChecker::lookupMember
findAutoDiffOriginalFunctionDecl
typeCheckDerivativeAttr
DerivativeAttrOriginalDeclRequest::evaluate

This patch fixes the issue by adding a check against ErrorType in findAutoDiffOriginalFunctionDecl before calling lookupMember.

@kovdan01
Copy link
Author

Tagging @asl

@kovdan01 kovdan01 marked this pull request as ready for review October 23, 2024 09:01
@asl
Copy link
Contributor

asl commented Oct 23, 2024

@swift-ci please test

@asl asl requested a review from rxwei October 23, 2024 16:36
lib/Sema/TypeCheckAttr.cpp Outdated Show resolved Hide resolved
@asl
Copy link
Contributor

asl commented Oct 23, 2024

@swift-ci please test

kovdan01 and others added 2 commits October 28, 2024 08:08
… search

Consider:

1. File struct.swift defining `struct Struct` with `static func max`
   member
2. File derivatives.swift defining `extension Struct` with custom
   derivative of the `max` function
3. File error.swift defining a differentiable function which uses
   `Struct.max`.

Previously, when passing error.swift as primary file and
derivatives.swift as a secondary file to swift-frontend (and forgetting
to pass struct.swift as a secondary file as well), an assertion failure
was triggered in the following call stack:

```
assert(type->mayHaveMembers()); // while type is ErrorType
TypeChecker::lookupMember
findAutoDiffOriginalFunctionDecl
typeCheckDerivativeAttr
DerivativeAttrOriginalDeclRequest::evaluate
```

This patch fixes the issue by adding a check against `ErrorType` in
`findAutoDiffOriginalFunctionDecl` before calling `lookupMember`.
Co-authored-by: Anton Korobeynikov <[email protected]>
@kovdan01 kovdan01 force-pushed the fix-assert-custom-derivatives branch from 0e6a3af to bcedb71 Compare October 28, 2024 05:09
@kovdan01 kovdan01 requested a review from asl October 28, 2024 05:11
@asl
Copy link
Contributor

asl commented Oct 28, 2024

@swift-ci please test

@kovdan01
Copy link
Author

@slavapestov @rxwei @hborla @xedin Would be glad to see your feedback on the changes.

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.

2 participants