Skip to content

[6.1] Introduce a new Initializer subclass for the arguments of custom attributes #78031

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

Conversation

DougGregor
Copy link
Member

@DougGregor DougGregor commented Dec 6, 2024

@DougGregor DougGregor requested a review from a team as a code owner December 6, 2024 23:18
@DougGregor
Copy link
Member Author

@swift-ci please test

…ibutes

Since the introduction of custom attributes (as part of property
wrappers), we've modeled the context of expressions within these
attributes as PatternBindingInitializers. These
PatternBindingInitializers would get wired in to the variable
declarations they apply to, establishing the appropriate declaration
context hierarchy. This worked because property wrappers only every
applied to---you guessed it!---properties, so the
PatternBindingInitializer would always get filled in.

When custom attributes were extended to apply to anything for the
purposes of macros, the use of PatternBindingInitializer became less
appropriate. Specifically, the binding declaration would never get
filled in (it's always NULL), so any place in the compiler that
accesses the binding might have to deal with it being NULL, which is a
new requirement. Few did, crashes ensued.

Rather than continue to play whack-a-mole with the abused
PatternBindingInitializer, introduce a new CustomAttributeInitializer
to model the context of custom attribute arguments. When the
attributes are assigned to a declaration that has a
PatternBindingInitializer, we reparent this new initializer to the
PatternBindingInitializer. This helps separate out the logic for
custom attributes vs. actual initializers.

Fixes swiftlang#76409 / rdar://136997841
…operties

We don't need to share them, and it's far simpler if we don't.
@DougGregor DougGregor force-pushed the custom-attribute-initializer-declcontext-6.1 branch from 26085ff to a0f043d Compare December 7, 2024 01:43
@DougGregor
Copy link
Member Author

@swift-ci please test

1 similar comment
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor DougGregor force-pushed the custom-attribute-initializer-declcontext-6.1 branch from e4e83d0 to b4465ee Compare December 7, 2024 07:03
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@swift-ci please test platform Windows

@DougGregor
Copy link
Member Author

Windows failure doesn't ring a bell:

# .---command stderr------------
# | Traceback (most recent call last):
# |   File "<string>", line 1, in <module>
# |   File "c:\program files (x86)\microsoft visual studio\shared\python39_64\lib\multiprocessing\spawn.py", line 116, in spawn_main
# |     exitcode = _main(fd, parent_sentinel)
# |   File "c:\program files (x86)\microsoft visual studio\shared\python39_64\lib\multiprocessing\spawn.py", line 126, in _main
# |     self = reduction.pickle.load(from_parent)
# |   File "c:\program files (x86)\microsoft visual studio\shared\python39_64\lib\multiprocessing\connection.py", line 967, in rebuild_pipe_connection
# |     handle = dh.detach()
# |   File "c:\program files (x86)\microsoft visual studio\shared\python39_64\lib\multiprocessing\reduction.py", line 131, in detach
# |     return _winapi.DuplicateHandle(
# | PermissionError: [WinError 5] Access is denied
# | Traceback (most recent call last):
# |   File "<string>", line 1, in <module>
# |   File "c:\program files (x86)\microsoft visual studio\shared\python39_64\lib\multiprocessing\spawn.py", line 107, in spawn_main
# |     new_handle = reduction.duplicate(pipe_handle,
# |   File "c:\program files (x86)\microsoft visual studio\shared\python39_64\lib\multiprocessing\reduction.py", line 79, in duplicate
# |     return _winapi.DuplicateHandle(
# | PermissionError: [WinError 5] Access is denied
# | Traceback (most recent call last):
# |   File "<string>", line 1, in <module>
# |   File "c:\program files (x86)\microsoft visual studio\shared\python39_64\lib\multiprocessing\spawn.py", line 107, in spawn_main
# |     new_handle = reduction.duplicate(pipe_handle,
# |   File "c:\program files (x86)\microsoft visual studio\shared\python39_64\lib\multiprocessing\reduction.py", line 79, in duplicate
# |     return _winapi.DuplicateHandle(
# | PermissionError: [WinError 5] Access is denied
# `-----------------------------

@DougGregor
Copy link
Member Author

@swift-ci please test Windows

@DougGregor DougGregor merged commit 0cd27f0 into swiftlang:release/6.1 Dec 8, 2024
5 checks passed
@DougGregor DougGregor deleted the custom-attribute-initializer-declcontext-6.1 branch December 8, 2024 16:47
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