Commit Graph

54 Commits

Author SHA1 Message Date
Doug Gregor
2a7de1b559 Store the conforming type within an abstract ProtocolConformanceRef
An "abstract" ProtocolConformanceRef is a conformance of a type
parameter or archetype to a given protocol. Previously, we would only
store the protocol requirement itself---but not track the actual
conforming type, requiring clients of ProtocolConformanceRef to keep
track of this information separately.

Record the conforming type as part of an abstract ProtocolConformanceRef,
so that clients will be able to recover it later. This is handled by a uniqued
AbstractConformance structure, so that ProtocolConformanceRef itself stays one
pointer.

There remain a small number of places where we create an abstract
ProtocolConformanceRef with a null type. We'll want to chip away at
those and establish some stronger invariants on the abstract conformance
in the future.
2025-03-23 20:53:48 -07:00
Doug Gregor
ffca6968ed [Isolated conformances] Diagnose conflict with isolated conformances and Sendable 2025-02-28 13:08:35 -08:00
Slava Pestov
e8d717bcd6 AST: Remove ModuleDecl parameter from checkRequirements() 2024-07-06 12:05:46 -04:00
Joe Groff
73e4c6fecd IRGen: Don't encode conditional requirements to Copyable as normal conformance requirements.
For new runtimes, this is redundant with the invertible requirement encoding, and for
old runtimes, this breaks dynamic conformance checking because Copyable and Escapable
aren't real protocols on those older runtimes. Fixes rdar://129857284.
2024-06-20 19:01:03 -07:00
Kavon Farvardin
55edc30528 NFC: expose an InverseRequirement::print 2024-03-14 23:10:44 -07:00
Kavon Farvardin
215bd3cab4 Mangling: handle inverse requirements 2024-03-05 14:19:00 -08:00
Joe Groff
fe7049ed13 SIL: More accurate for type lowering whether a type is trivial based on conditional Copyable requirements.
We want a conditionally-copyable type to still be classified as trivial in cases
where it's bitwise-copyable, has a trivial deinit, and is Copyable. The previous
implementation here only checked at the declaration level whether a type was
Copyable or not; get a more accurate answer by consulting the combination
of information in the substituted type and abstraction pattern we have
available during type lowering so that we classify definitely-copyable substitutions
of a conditionally-copyable type as trivial. Should fix rdar://123654553 and
rdar://123658878.
2024-02-27 15:01:20 -08:00
Slava Pestov
76670472dc AST: Remove InverseRequirement::enumerateDefaultedParams() 2024-02-24 07:25:59 -05:00
Slava Pestov
7204a692a4 AST: Clean up ExistentialLayout construction 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
Kavon Farvardin
5e51773718 NCGenerics: find conflicts in PCT's
We weren't diagnosing conflicts in PCT's like `Copyable & ~Copyable`,
instead deferring until that PCT was constrained to something like the
existential Self or a generic parameter, which then we'd diagnose.

But we should canonicalize PCT's such as `Copyable & Copyable` into
`Any`, which represents the empty composition. That's what the assert in
 PCT::build is about.
2024-02-08 15:56:50 -08:00
Slava Pestov
d2f136254e AST: Remove fromDefault and inferred from StructuralRequirement 2024-02-02 14:57:20 -05:00
Slava Pestov
1e950b1725 AST: Move checkGenericArguments() to AST and rename to checkRequirements() 2024-01-16 14:47:50 -05:00
Kavon Farvardin
bd1330715c [NCGenerics] only print ~Copyable in interface
We can't simply emit the desugared, expanded version of the requirements
because there's no way to pretty-print the type `some ~Copyable` when
the `~Copyable`'s get replaced with the absence of `Copyable`. We'd be
left with just `some _` or need to invent a new top type so we can write
`some Top`. Thus, it's best to simply reverse the expansion of default
requirements when emitting a swiftinterface file.
2023-12-12 16:40:26 -08:00
Kavon Farvardin
63b3e7624d [NCGenerics] fold InverseType into PCT
We already need to track the inverses separate from the members in a
ProtocolCompositionType, since inverses aren't real types. Thus, the
only purpose being served by InverseType is to be eliminated by
RequirementLowering when it appears in a conformance requirement.

Instead, we introduce separate type InverseRequirement just to keep
track of which inverses we encounter to facilitate cancelling-out
defaults and ensuring that the inverses are respected after running
the RequirementMachine.
2023-12-07 22:14:23 -08:00
Slava Pestov
b6b51cf4cf AST: Checking of pack requirements 2023-03-17 22:18:55 -04:00
Slava Pestov
d27231a91c AST: Generalize Requirement::isSatisfied() to Requirement::checkRequirement() 2023-03-17 22:18:55 -04:00
Slava Pestov
affd1bf8fd AST: Fold RequirementBase into it's three subclasses
It's a very simple algebraic data type, and factoring it out into
a template doesn't carry its weight.
2023-03-09 01:54:51 -05:00
Holly Borla
38a2c8218b [Requirement] Rename RequirementKind::SameCount to SameShape. 2022-10-06 20:48:40 -07:00
Slava Pestov
5c32f2136e AST: Introduce RequirementKind::SameCount 2022-08-23 11:12:00 -04:00
Slava Pestov
7d8f3e6b63 AST: Change return type of Requirement::subst() to Requirement
Instead of returning None, let callers check hasError() if they need to.

Fixes rdar://problem/98565072.
2022-08-12 14:03:57 -04:00
Slava Pestov
d8393bc287 AST: Add Requirement::hasError() utility method 2022-04-01 21:40:40 -04:00
Slava Pestov
1d427eaa12 AST: Add request to compute protocol structural requirements and dependencies
These will be used by the RequirementMachine to compute requirement
signatures. For now, they're not hooked up.

ProtocolDecl::getStructuralRequirements() produces a list of Requirements
with SourceLocs from the structural types written in the protocol's
inheritance clause and 'where' clauses.

ProtocolDecl::getProtocolDependencies() produces a list of protocols which
appear on the right hand side of the protocol's conformance requirements.
2021-09-28 14:31:32 -04:00
Slava Pestov
fd7759ff68 AST: Move Requirement::compare() to GenericSignature.cpp 2021-08-11 12:01:07 -04:00
Doug Gregor
f9c34756ef Parameterize conformance lookup on whether "missing" conformances are allowed.
Many clients of the conformance lookup operations would prefer to get
an invalid conformance (== there is no conformance) rather than a
missing conformance. Parameterize the conformance lookup operations so
that most callers won't see missing conformances, by filtering them
out at the end. Opt-in those callers that do want to see missing
conformances so they can be diagnosed.
2021-08-03 00:10:45 -07:00
Slava Pestov
fe06df8288 AST: Move guts of checkGenericArguments() to a new Requirement::isSatisfied() method 2021-05-17 16:34:17 -04:00
Slava Pestov
53e06d69b5 AST: Factor out a new Requirement::getProtocolDecl() utility method 2021-02-25 17:21:18 -05:00
Adrian Prantl
6fb61785c1 Support SILBoxWithLayout in TypeDecoder and factor out decodeRequirement() from
ASTBuilder.
2021-02-03 14:23:54 -08:00
Hamish Knight
ff61b24b36 Remove Type's hash_value function
Defining `hash_value` for `Type` makes it easy to
forget that the underlying pointer is being hashed
directly without canonicalization.

Instead, define it only for `CanType`, and make
`Type` users spell `getPointer` explicitly.
2020-06-15 17:44:50 -07:00
Brent Royal-Gordon
99faa033fc [NFC] Standardize dump() methods in frontend
By convention, most structs and classes in the Swift compiler include a `dump()` method which prints debugging information. This method is meant to be called only from the debugger, but this means they’re often unused and may be eliminated from optimized binaries. On the other hand, some parts of the compiler call `dump()` methods directly despite them being intended as a pure debugging aid. clang supports attributes which can be used to avoid these problems, but they’re used very inconsistently across the compiler.

This commit adds `SWIFT_DEBUG_DUMP` and `SWIFT_DEBUG_DUMPER(<name>(<params>))` macros to declare `dump()` methods with the appropriate set of attributes and adopts this macro throughout the frontend. It does not pervasively adopt this macro in SILGen, SILOptimizer, or IRGen; these components use `dump()` methods in a different way where they’re frequently called from debugging code. Nor does it adopt it in runtime components like swiftRuntime and swiftReflection, because I’m a bit worried about size.

Despite the large number of files and lines affected, this change is NFC.
2019-10-31 18:37:42 -07:00
Sasha Krassovsky
1e414f7fb6 Fix warnings in AST 2019-09-13 09:57:48 -07:00
Doug Gregor
8ad76a1707 Canonicalize requests for the abstract generic signature.
When a request for an abstract generic signature contains noncanonical
types, first compute the abstract generic signature for the
canonicalized types, then map back to the provided generic
parameters. Clients of this request generally work in canonical types
already, but it's a small win.
2019-08-26 09:54:20 -07:00
Doug Gregor
a23a4353cb [Type checker] Requestify the formation of an abstract generic signature
Introduce a request to form an abstract generic signature given a
base signature, additional generic parameters, and additional
requirements. It is meant to provide a caching layer in front of the
generic signature builder.

Switch one direct client of the generic signature builder over to this
mechanism, the formation of a generic signature for an existential
type.
2019-08-26 09:54:19 -07:00
Slava Pestov
2dbeeb0d3f AST: Make SubstFlags::UseErrorType the default behavior
We've fixed a number of bugs recently where callers did not expect
to get a null Type out of subst(). This occurs particularly often
in SourceKit, where the input AST is often invalid and the types
resulting from substitution are mostly used for display.

Let's fix all these potential problems in one fell swoop by changing
subst() to always return a Type, possibly one containing ErrorTypes.

Only a couple of places depended on the old behavior, and they were
easy enough to change from checking for a null Type to checking if
the result responds with true to hasError().

Also while we're at it, simplify a few call sites of subst().
2019-08-22 01:07:50 -04:00
Adrian Prantl
ff63eaea6f Remove \brief commands from doxygen comments.
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.

Patch produced by

      for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
2018-12-04 15:45:04 -08:00
Huon Wilson
ade976893e [AST] Test conditional requirement selection by having -debug-generic-signatures include conformances.
And make conformances' dump include the conditional requirements too.
2017-10-10 20:17:39 -07:00
Slava Pestov
5efe9e8134 Sema: Fix latent bug in TypeChecker::checkGenericArguments()
We were passing an already-substituted type to subst().

This is about to become an error, so fix the code to do
the right thing.
2017-04-03 20:41:31 -07:00
Hugh Bellamy
33f5f89912 Update unreachable control path annotations 2017-03-03 20:21:49 +07:00
Huon Wilson
f1dba0e7e8 [Generic signature builder] Substitute requirements instead of threading a PA around.
This essentially undoes the implementation in 51da51dfc0, which
implicitly did a substitution of the Self type in a protocol's
requirement signature by threading around the replacement PA. This is
brittle because every part of the code needs to take and pass around the
argument. By preemptively substituting, the whole requirement is in the
right form from the time it enters `addRequirement`.

The infrastructure here also allows simplifying some code.
2017-02-10 18:58:56 -08:00
Roman Levenstein
29180ca1a0 Add support for layout requirements with layout constraints.
This commit introduces new kind of requirements: layout requirements.

This kind of requirements allows to expose that a type should satisfy certain layout properties, e.g. it should be a trivial type, have a given size and alignment, etc.
2017-01-11 19:21:45 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Doug Gregor
84d70a2284 Eliminate witness markers. NFC 2016-11-09 19:22:51 -08:00
Slava Pestov
cfe9e6a3de IDE: Use GenericSignatures and interface types (mostly)
There was a ton of complicated logic here to work around
two problems:

- Same-type constraints were not represented properly in
  RequirementReprs, requiring us to store them in strong form
  and parse them out when printing type interfaces.

- The TypeBase::getAllGenericArgs() method did not do the
  right thing for members of protocols and protocol extensions,
  and so instead of simple calls to Type::subst(), we had
  an elaborate 'ArchetypeTransformer' abstraction repeated
  in two places.

Rewrite this code to use GenericSignatures and
GenericFunctionType instead of old-school GenericParamLists
and PolymorphicFunctionType.

This changes the code completion and AST printer output
slightly. A few of the changes are actually fixes for cases
where the old code didn't handle substitutions properly.
A few others are subjective, for example a generic parameter
list of the form <T : Proto> now prints as <T where T : Proto>.

We can add heuristics to make the output whatever we want
here; the important thing is that now we're using modern
abstractions.
2016-10-02 23:49:15 -04:00
Slava Pestov
fb347db4fa AST: Add dump() method to Requirement and GenericEnvironment 2016-09-06 11:51:11 -07:00
Slava Pestov
5aa22f3d89 AST: Add some assertions, NFC
Easier to debug if we crash when constructing an invalid Requirement
rather than later on when we try to do something with it.
2016-06-16 22:51:45 -07:00
Dmitri Gribenko
a9f8d97d3e Replace 'unsigned int' with 'unsigned'
'unsigned' is more idiomatic in LLVM style.
2016-02-27 16:20:27 -08:00
John McCall
1f3b3142b4 Distinguish conformance and superclass generic requirements.
As part of this, use a different enum for parsed generic requirements.

NFC except that I noticed that ASTWalker wasn't visiting the second
type in a conformance constraint; fixing this seems to have no effect
beyond producing better IDE annotations.
2016-01-11 16:07:37 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Dmitri Hrybenko
ce34e9f070 Use an appropriate number of bits to store RequirementKind
Found by static analysis, so, unfortunately, no test

Swift SVN r22343
2014-09-28 19:09:21 +00:00