Commit Graph

48 Commits

Author SHA1 Message Date
Becca Royal-Gordon
9be9b6fad6 Inherit access control in @abi
ABI-only declarations now inherit access control modifiers like `public` or `private(set)`, as well as `@usableFromInline` and `@_spi`, from their API counterpart. This means these attributes and modifiers don’t need to be specified in an `@abi` attribute.

Very few tests because we aren’t yet enforcing the absence of these attributes.
2025-03-26 10:47:13 -07:00
Nate Chandler
091368ba21 [CoroutineAccessors] Added read.
The name is a placeholder for the mutating single-yield coroutine
accessor.
2024-09-26 18:10:39 -07:00
Nate Chandler
98a2e6a7df [CoroutineAccessors] Added modify.
The name is a placeholder for the mutating single-yield coroutine
accessor.
2024-09-26 18:10:39 -07:00
Pavel Yaskevich
dbe151bc0f [AST] Mark init accessors as having internal access
This allows them to be used across files in the same module
and requires explicit `@usableFromInline` annotation to be
used inside of `@_alwaysEmitIntoClient` and `@inlinable`
initializers.
2024-07-11 14:03:11 -07:00
Tim Kientzle
598e5104ef Merge pull request #74184 from tbkka/tbkka-assertions2
Add `#include "swift/Basic/Assertions.h"` to a lot of source files
2024-06-20 12:13:28 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
li3zhen1
da5dd94bb7 [AST] Allow Init accessors to be internal 2024-05-02 19:52:13 -07:00
Konrad `ktoso` Malawski
6132386371 [Distributed] Complete handling of protocol calls and witnesses using adjusted mangling scheme (#72416) 2024-03-23 23:54:23 +09:00
Slava Pestov
7909d83229 AST: Refactor directReferencesForTypeRepr() to track inverses 2024-02-24 07:25:59 -05:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Hamish Knight
3f4b45b012 [AST] Remove SerializedLocalDeclContext
It's not clear that its worth keeping this as a
base class for SerializedAbstractClosure and
SerializedTopLevelCodeDecl, most clients are
interested in the concrete kinds, not only whether
the context is serialized.
2024-01-18 12:03:52 +00:00
Evan Wilde
b0e454f682 Fix broken access levels
I had an off-by-one in
`DefaultAndMaxAccessLevelRequest::getCachedResult`. The original code
added 1 to the last and first set bits when computing the `Max` and
`Default` access levels:

AccessLevel Max = static_cast<AccessLevel>(llvm::findLastSet(Bits) + 1);
AccessLevel Default = static_cast<AccessLevel>(llvm::findFirstSet(Bits) + 1);

LLVM got rid of `findLastSet`, so in the fun of figuring out the
replacements (llvm::countl_zero and llvm::countl_zero), I missed adding
the one to the result.
2023-07-27 11:40:15 -07:00
Evan Wilde
2705049432 Replace find{First,Last}Set functions
LLVM removed findFirstSet and findLastSet functions from MathExtras and
doesn't have a direct replacement. We only have once instance of these
functions used in the compiler, so I've replaced them inline with the
appropriate bit operations.
2023-07-17 10:53:42 -07:00
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Allan Shortlidge
775b4a47c0 AST: Inherit access level of opaque type decls from naming decl.
When an `OpaqueTypeDecl` is constructed, the access level attributes of the
decl that names the opaque type were copied on to it. However, the
`@usableFromInline` attribute is not permitted on every decl, so it does not
get copied. This in turn causes access level computations for opaque types to
fail to take `@usableFromInline` into account and that results in the emitted
symbol getting the wrong linkage during IRGen. The fix is to make access level
computations take this quirk of opaque types into account directly (like they
already to for several other kinds of decls), instead of relying on copying of
attributes.

Resolves rdar://110544170
2023-06-12 12:05:25 -07:00
Holly Borla
684ef9c482 [AST] Add a new accessor kind for init accessors. 2023-06-06 18:57:31 -07:00
Ellie Shin
7d23db3646 Create PackageUnit class, and Package entries to DeclContext / ASTHierarchy
Previously enum AccessLimitKind was
added to distinguish access scopes b/t package and public while keeping
DeclContext null but it proved to be too limiting. This PR creates package specific entries for DeclContext and
ASTHierarchy. It create a new class PackageUnit that can be set as the parent DeclContext of ModuleDecl. This PR
contains addition of such entries but not the use of them; the actual use of them will be in the upcoming PRs.

Resolves rdar://106155600
2023-03-02 13:20:51 -08:00
Ellie Shin
1c66d02f92 Add package access level to enum AccessLevel
Resolves rdar://104198440
2023-01-19 15:54:18 -08:00
Doug Gregor
4ce0834c51 [Macros] Serialization support for macro declarations. 2022-11-28 18:33:09 -08:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Doug Gregor
5ab6b72604 [Macros] Turn Macro into a declaration node.
Although the declaration of macros doesn't appear in Swift source code
that uses macros, they still operate as declarations within the
language. Rework `Macro` as `MacroDecl`, a generic value declaration,
which appropriate models its place in the language.

The vast majority of this change is in extending all of the various
switches on declaration kinds to account for macros.
2022-11-13 12:21:29 -08:00
Becca Royal-Gordon
ad359fa753 Give @_objcImpl classes implicit deinits 2022-10-18 17:21:56 -07:00
Robert Widmann
eba9bbe36b Use the Formal Access *Scope* of the Extended Nominal For Its Max Access
Formal access alone does not take into account @testable imports of
internal types. This prevented otherwise valid conditional conformances
of these types from compiling.

rdar://72875683
2021-01-15 17:10:49 -08:00
Robert Widmann
987cd55f50 [NFC] Drop llvm::Expected from Evaluation Points
A request is intended to be a pure function of its inputs. That function could, in theory, fail. In practice, there were basically no requests taking advantage of this ability - the few that were using it to explicitly detect cycles can just return reasonable defaults instead of forwarding the error on up the stack.

This is because cycles are checked by *the Evaluator*, and are unwound by the Evaluator.

Therefore, restore the idea that the evaluate functions are themselves pure, but keep the idea that *evaluation* of those requests may fail. This model enables the best of both worlds: we not only keep the evaluator flexible enough to handle future use cases like cancellation and diagnostic invalidation, but also request-based dependencies using the values computed at the evaluation points. These aforementioned use cases would use the llvm::Expected interface and the regular evaluation-point interface respectively.
2020-03-26 23:08:02 -07:00
Robert Widmann
3bd0044143 [Gardening] Remove remaining casting artifacts 2020-02-07 16:09:31 -08:00
Robert Widmann
d2360d2e8c [Gardening] dyn_cast -> isa 2020-02-07 16:09:31 -08:00
Robert Widmann
0267384e11 Fixup SourceKit and Tests
Patch up all the places that are making a syntactic judgement about the
isInvalid() bit in a ValueDecl.  They may continue to use that query,
but most guard themselves on whether the interface type has been set.
2019-10-30 15:09:14 -07:00
Jordan Rose
8d7f1b7c5d [AST] Separate SourceFile from FileUnit.h
Like the last commit, SourceFile is used a lot by Parse and Sema, but
less so by the ClangImporter and (de)Serialization. Split it out to
cut down on recompilation times when something changes.

This commit does /not/ split the implementation of SourceFile out of
Module.cpp, which is where most of it lives. That might also be a
reasonable change, but the reason I was reluctant to is because a
number of SourceFile members correspond to the entry points in
ModuleDecl. Someone else can pick this up later if they decide it's a
good idea.

No functionality change.
2019-09-17 17:54:41 -07:00
Jordan Rose
853caa66d4 [AST] Split FileUnit and its subclasses out of Module.h
Most of AST, Parse, and Sema deal with FileUnits regularly, but SIL
and IRGen certainly don't. Split FileUnit out into its own header to
cut down on recompilation times when something changes.

No functionality change.
2019-09-17 17:54:41 -07:00
Robert Widmann
087e2f2746 [Evaluator Ergonomics] Add location information options to the requests 2019-09-06 11:16:17 -07:00
Robert Widmann
7a51cfcb87 [Evaluator Ergonomics] Add Request Signatures
Also add their caching kinds.  This information will be used to remove
the need to define classes at all.
2019-09-05 13:15:02 -07:00
Robert Widmann
a19a70e5c9 Switch all request infrastructure to SWIFT_REQUEST
Formally define the Zones in the TypeID header.  This is not its final
resting place.
2019-08-27 17:38:14 -07:00
Slava Pestov
0c5d52d860 AST: Introduce AbstractStorageDecl::get{Parsed,Opaque}Accessor()
Also, change visitOpaqueAccessors() to call getOpaqueAccessor() instead of
asserting if the expected accessor does not exist.
2019-08-02 19:34:43 -04:00
Slava Pestov
64c32c695b AST: Remove a few utility methods from AbstractStorageDecl
Since the return value of getAccessor() depends on mutable state, it
does not make sense in the request evaluator world. Let's begin by
removing some utility methods derived from getAccessor(), replacing
calls to them with calls to getAccessor().
2019-08-01 18:31:58 -04:00
Slava Pestov
56f8f05f95 AST: Move 'private set' attribute computation to SetterAccessLevelRequest 2019-07-23 16:13:28 -04:00
Doug Gregor
39d4e6b41d [Request-evaluator] Remove extraneous diagnoseCycle/noteCycleStep impls.
All of these can use the default implementations now.
2019-07-10 17:26:39 -07:00
Robert Widmann
c5b7230d22 [NFC] Upgrade EnumElementDecl to a DeclContext
Pure plumbing for the sake of default arguments.
2019-01-16 18:39:30 -05:00
Saleem Abdulrasool
d281b98220 litter the tree with llvm_unreachable
This silences the instances of the warning from Visual Studio about not all
codepaths returning a value.  This makes the output more readable and less
likely to lose useful warnings.  NFC.
2018-09-13 15:26:14 -07:00
Slava Pestov
b4962e16b5 Sema: Remove setAccess() call from prepareGenericParamList() 2018-09-05 16:50:13 -07:00
Slava Pestov
cdadee8173 AST: Fix layering violations in DefaultAndMaxAccessLevelRequest
Our walk over the requirement interface types meant that
computing the access level of an extension member depended
on type resolution and the GSB.

Fix this by adding a new request that simply collects all
TypeDecls referenced from a TypeRepr, and compute the
extension's maximum access level using that.

If we use Structural rather than Interface type resolution when
walking the extension's requirements, we don't have to build its
generic signature first.
2018-09-05 16:18:54 -07:00
John McCall
b80618fc80 Replace materializeForSet with the modify coroutine.
Most of this patch is just removing special cases for materializeForSet
or other fairly mechanical replacements.  Unfortunately, the rest is
still a fairly big change, and not one that can be easily split apart
because of the quite reasonable reliance on metaprogramming throughout
the compiler.  And, of course, there are a bunch of test updates that
have to be sync'ed with the actual change to code-generation.

This is SR-7134.
2018-08-27 03:24:43 -04:00
Doug Gregor
3c54886c4d [Type checker] Use RequirementRequest::visitRequirements() more intentionally.
Rather than using RequirementRequest::visitRequirements() for its side
effects, then reading from the TypeLocs left behind, start eliminating
TypeLoc-based APIs so we pass Type and TypeRepr separately.

Add some utilities to dig into a possibly-null RequirementRepr* and dig
out the appropriate TypeReprs.
2018-08-23 15:14:19 -07:00
Doug Gregor
7e96f123b9 [Type checker] Make sure we check access of ‘where’ clauses properly. 2018-08-23 13:42:09 -07:00
Harlan Haskins
5a6985f39e Remove SimpleRequest::breakCycle
This patch removes the need for Request objects to provide a default
cycle-breaking value, instead opting to return llvm::Expected so clients
must handle a cycle failure explicitly.

Currently, all clients do the 'default' behavior, but this opens the
possibility for future requests to handle failures explicitly.
2018-08-15 11:01:12 -07:00
Doug Gregor
bd5f5d80e4 [AST] Add ExtensionDecl::getExtendedNominal().
Introduce ExtensionDecl::getExtendedNominal() to provide the nominal
type declaration that the extension declaration extends. Move most
of the existing callers of the callers to getExtendedType() over to
getExtendedNominal(), because they don’t need the full type information.

ExtensionDecl::getExtendedNominal() is itself not very interesting yet,
because it depends on getExtendedType().
2018-08-03 11:26:48 -07:00
John McCall
7a4aeed570 Implement generalized accessors using yield-once coroutines.
For now, the accessors have been underscored as `_read` and `_modify`.
I'll prepare an evolution proposal for this feature which should allow
us to remove the underscores or, y'know, rename them to `purple` and
`lettuce`.

`_read` accessors do not make any effort yet to avoid copying the
value being yielded.  I'll work on it in follow-up patches.

Opaque accesses to properties and subscripts defined with `_modify`
accessors will use an inefficient `materializeForSet` pattern that
materializes the value to a temporary instead of accessing it in-place.
That will be fixed by migrating to `modify` over `materializeForSet`,
which is next up after the `read` optimizations.

SIL ownership verification doesn't pass yet for the test cases here
because of a general fault in SILGen where borrows can outlive their
borrowed value due to being cleaned up on the general cleanup stack
when the borrowed value is cleaned up on the formal-access stack.
Michael, Andy, and I discussed various ways to fix this, but it seems
clear to me that it's not in any way specific to coroutine accesses.

rdar://35399664
2018-07-23 18:59:58 -04:00
Graydon Hoare
465ca073f8 [Sema] Move AccessLevel calculation to AST-level requests. 2018-07-04 16:56:26 -07:00