Commit Graph

1132 Commits

Author SHA1 Message Date
Slava Pestov
e7e536705e AST: Introduce ParametrizedProtocolType 2022-01-26 00:11:38 -05:00
Doug Gregor
452eccab83 Remove NestedArchetypeType.
Nested archetypes are represented by their base archetype kinds (primary,
opened, or opaque type) with an interface type that is a nested type,
as represented by a DependentMemberType. This provides a more uniform
representation of archetypes throughout the frontend.
2022-01-14 21:28:21 -08:00
Doug Gregor
8df65e706e Remove unnecessary uses of NestedArchetypeType.
`ArchetypeType` has all of the API we need for these cases, so use
that instead to isolate us from `NestedArchetypeType`, which we would
like to eliminate soon-ish.
2022-01-14 21:25:32 -08:00
Holly Borla
992a871a73 [Type Reconstruction] Re-construct existential types with ExistentialType
by propagating whether the decoded type is for a requirement through
TypeDecoder.
2022-01-13 19:31:37 -08:00
Holly Borla
f7a82ac174 [Type Reconstruction] For now, reconstruct existential types without
explicit ExistentialType.

The ASTDemangler needs to produce ExistentialType based on context, not
unconditionally when producing a protocol composition. This is tricky
because existential types are mangled the same way as other protocol
references, e.g. in conformance requirements. For now, drop the explicit
existentials when reconstructing types.
2022-01-13 19:30:44 -08:00
adrian-prantl
324cccd18e Merge pull request #40670 from adrian-prantl/77344315
Fix the module hash stored in -gmodules skeleton units
2021-12-22 11:43:48 -08:00
Adrian Prantl
1adb0b301a Fix the module hash stored in -gmodules skeleton units
by using the proper API. The old code produced the address of the hash.  This
fixes a warning printed by LLDB and dsymutil about module hash mismatches and
makes the build build products more deterministic.

rdar://77344315
2021-12-21 15:53:57 -08:00
Robert Widmann
e5bfda7c6e Merge pull request #40587 from CodaFi/substitute-teacher
Initial Semantics for Variadic Generics
2021-12-20 11:25:25 -08:00
Alex Hoppen
669e3f34a6 Merge pull request #40155 from ahoppen/pr/improve-module-search-path-lookup
[Serialization] Improve module loading performance
2021-12-20 18:09:17 +01:00
Robert Widmann
06bc38f5a2 Model PackExpansion Types
A PackExpansionType is the interface type of the explicit expansion of a
corresponding set of variadic generic parameters.
Pack expansions are spelled as single-element tuples with a single variadic
component in most contexts except functions where they are allowed to appear without parentheses to match normal variadic declaration syntax.

```
func expand<T...>(_ xs: T...) -> (T...)
                        ~~~~     ~~~~~~
```

A pack expansion type comes equipped with a pattern type spelled before
the ellipses - `T` in the examples above. This pattern type is the subject
of the expansion of the pack that is tripped when its variadic generic
parameter is substituted for a `PackType`.
2021-12-16 00:34:09 -08:00
Robert Widmann
746aa1fb58 Model Pack Types
A pack type looks a lot like a tuple in the surface language, except there
is no way for the user to spell a pack. Pack types are created by the solver
when it encounters an apply of a variadic generic function, as in

```
func print<T...>(_ xs: T...) {}
// Creates a pack type <String, Int, String>
print("Macs say Hello in", 42, " different languages")
```

Pack types substituted into the variadic generic arguments of a
PackExpansionType "trip" the pack expansion and cause it to produce a
new pack type with the pack expansion pattern applied.

```
typealias Foo<T...> = (T?...)
Foo<Int, String, Int> // Forces expansion to (Int?, String?, Int?)
```
2021-12-16 00:25:34 -08:00
Alex Hoppen
fe7878ecce [Serialization] Improve module loading performance
When looking for a Swift module on disk, we were scanning all module search paths if they contain the module we are searching for. In a setup where each module is contained in its own framework search path, this scaled quadratically with the number of modules being imported. E.g. a setup with 100 modules being imported form 100 module search paths could cause on the order of 10,000 checks of `FileSystem::exists`. While these checks are fairly fast (~10µs), they add up to ~100ms.

To improve this, perform a first scan of all module search paths and list the files they contain. From this, create a lookup map that maps filenames to the search paths they can be found in. E.g. for
```
searchPath1/
  Module1.framework

searchPath2/
  Module1.framework
  Module2.swiftmodule
```
we create the following lookup table
```
Module1.framework -> [searchPath1, searchPath2]
Module2.swiftmodule -> [searchPath2]
```
2021-12-14 12:44:13 +01:00
Holly Borla
445a856652 [Type System] Introduce a dedicated type to represent existential types.
The new type, called ExistentialType, is not yet used in type resolution.
Later, existential types written with `any` will resolve to this type, and
bare protocol names will resolve to this type depending on context.
2021-12-09 23:14:50 -08:00
Robert Widmann
e7e11df927 Model Sequence Archetypes 2021-11-16 11:38:57 -08:00
Adrian Prantl
bc8bb830a8 Add support for relative paths in debug prefix maps.
Users may want to use -fdebug-prefix-map to remap a directory to "./".
This wasn't supported previously and resulted in duplicate path
prefixes in the debug info.

With this patch swiftc behaves similar to clang when remapping a path
to a relative path.

rdar://83753143
2021-11-04 11:17:52 -07:00
zoecarver
bd71c84bd8 [cxx-interop] Disable round trip checking for C++ debug types.
This doesn't work for some C++ types, so, as a stop gap solution, I'm disabling it when C++ interop is enabled.

https://bugs.swift.org/browse/SR-15377 to re-enable it in the future.
2021-10-22 14:41:45 -07:00
Ellie Shin
5277a769e2 Merge pull request #39634 from apple/es-m5
Module aliasing: use module real name to create DIModule
2021-10-13 12:10:33 -07:00
elsh
317a766a80 Module aliasing: use module real name to create DIModule 2021-10-07 15:16:13 -07:00
Adrian Prantl
0e83389e35 Wrap assertion code in infndef NDEBUG to fix non-asserts build. 2021-09-24 14:48:22 -07:00
Adrian Prantl
dc50c93301 Handle missing DIExprOperator kinds in IRGenDebugInfo 2021-09-17 17:37:56 -07:00
Adrian Prantl
eb2b7ba4b8 Fix local variable uniquing to take into account tail-allocated variable names 2021-09-17 17:36:25 -07:00
Adrian Prantl
fd19e4bc07 Distinguish between storage size of a fragment and storage size for the entire
type in DebugTypeInfo.
2021-09-17 15:57:27 -07:00
Adrian Prantl
ea6dca3e94 Fix SIL Verifier 2021-09-10 17:07:02 -07:00
Min-Yih Hsu
69ffafe146 (Stash) Salvage debug info from deleted index_addr instruction
And calling `swift::salvageDebugInfo` in more places.

NOTE: The latter change seems to break stdlib build.
2021-09-10 14:17:38 -07:00
Min-Yih Hsu
a9cb668170 (Stash) basic IRGen support 2021-09-10 14:17:38 -07:00
Adrian Prantl
399a8b4864 Fix build for older compilers 2021-09-03 17:46:16 -07:00
Adrian Prantl
06c409d324 IRGenDebugInfo: Unique DILocalVariables. 2021-09-03 17:38:32 -07:00
swift-ci
ebad328a4f Merge remote-tracking branch 'origin/main' into rebranch 2021-09-01 09:14:57 -07:00
Min-Yih Hsu
33ec01a60c [SIL][DebugInfo] PATCH 1/3: Add support for expr op_deref
This new SIL di-expression represents the dereference on the SSA value.
Similar to DW_OP_deref in DWARF. It is also going to replace the
existing `debug_value_addr`. Namely, replacing the following
instruction:
```
debug_value_addr %a : $*T, name "my_var"
```
with this one:
```
debug_value %a : $*T, name "my_var", expr op_deref
```
2021-08-31 09:22:25 -07:00
swift-ci
5fe1881a91 Merge remote-tracking branch 'origin/main' into rebranch 2021-08-27 21:53:32 -07:00
Rintaro Ishizaki
49547a5378 [NFC][Basic] Import llvm::isa_and_nonnull to 'swift' namespace
Just for convenicence.

* Replace `llvm::isa_and_nonnull` with imported `isa_and_nonnull`
* Repalce some `EXPR && isa<T>(EXPR)` with `isa_and_nonnull<T>(EXPR)`
2021-08-27 11:36:21 -07:00
swift-ci
19048afbc8 Merge remote-tracking branch 'origin/main' into rebranch 2021-08-25 07:13:51 -07:00
Slava Pestov
cda25b7eeb IRGen: Mangle DWARF types with the right generic signature
The symptom here was a crash in getConformanceAccessPath(), but the root
cause was that the ASTMangler used an incorrect generic signature when
looking up the conformance path for a type parameter.

The mangler requires a generic signature to be set to properly mangle types
containing retroactive conformances. However, DebugInfo just used the
IRGenModule's current signature, which wasn't always the same as the
signature describing the archetypes found inside the SILFunction.

Fixes rdar://problem/81683650 / https://bugs.swift.org/browse/SR-15046.
2021-08-24 21:48:19 -04:00
Adrian Prantl
c40b8f38b8 Update IRGenDebugInfo for LLVM D95617.
In https://reviews.llvm.org/D95617 LLVM stopped to emit debug values without a
location as an optimization for inlined functions. Because Swift is emitting
dbg.values(undef) for sizeless variables even at -Onone, we need to make sure
all local variables are preserved even at -Onone.

rdar://82038523
2021-08-20 12:57:23 -07:00
Min-Yih Hsu
4361da6930 Merge pull request #38942 from mshockwave/dev-dbg-var-artificial
[DebugInfo] Prevent salvaged debug vars from being marked artificial
2021-08-20 11:05:11 -07:00
Min-Yih Hsu
da5ef903bd [DebugInfo] Prevent salvaged debug vars from being marked artificial
We were using compiler-generated source location (i.e. line number
0) on `debug_value` instructions were emitted by salvage debug info.
But it turned out that IRGen will attach DW_AT_artificial on the
associated debug variables, which are hidden in debugger by default.
This patch prevent this issue by using the source location from the
just-deleted instruction for these `debug_value` instructions.

This indirectly triggered another bug where some of the LLVM
!DIExpression-s we generated are actually invalid -- more specifically,
the fragment inside is covering the whole debug variable. The reason it was
not previously caught is because LLVM verifier skips any debug variable
that is marked artificial, and all debug variables that have illegal fragment
are falling under this category. Thus, this patch also fixes this issue
by not generating the DW_OP_LLVM_fragment part if it's illegal.
2021-08-19 13:21:40 -07:00
Robert Widmann
592e90af9b Add Sugar for Variadics
We used to represent the interface type of variadic parameters directly
with ArraySliceType. This was awfully convenient for the constraint
solver since it could just canonicalize and open [T] to Array<$T>
wherever it saw a variadic parameter. However, this both destroys the
sugaring of T... and locks the representation to Array<T>. In the
interest of generalizing this in the future, introduce
VariadicSequenceType. For now, it canonicalizes to Array<T> just like
the old representation. But, as you can guess, this is a new staging
point for teaching the solver how to munge variadic generic type bindings.

rdar://81628287
2021-08-06 12:51:39 -07:00
Min-Yih Hsu
9a8f2ed642 [SILOptimizer][DebugInfo] Preliminary support for DIExpression in SROA and Mem2Reg
SROA and Mem2Reg now can leverage DIExpression -- op_fragment, more
specifically -- to generate correct debug info for optimized SIL. Some
important highlights:
 - The new swift::salvageDebugInfo, similar to llvm::salvageDebugInfo,
   tries to restore / transfer debug info from a deleted instruction.
   Currently I only implemented this for store instruction whose
   destination is an alloc_stack value.
 - Since we now have source-variable-specific SIL location inside a
   `debug_value` instruction (and its friends), this patch teaches
   SILCloner and SILInliner to remap the debug scope there in addition
   to debug scope of the instruction.
 - DCE now does not remove `debug_value` instruction whose associating
   with a function argument SSA value that is not used elsewhere. Since
   that SSA value will not disappear so we should keep the debug info.
2021-08-05 17:27:45 -07:00
Min-Yih Hsu
2bb6498731 [SIL][DebugInfo] Bring advanced debug info to alloc_stack
The `alloc_stack` instruction now can carry advanced debug info like
source-variable-specific SIL location, type, and SIL DIExpression.
2021-08-04 12:56:25 -07:00
Min-Yih Hsu
5a42c27826 Merge pull request #38378 from mshockwave/dev-sil-diexpression
[DebugInfo] Adding DIExpression into SIL
2021-07-22 13:19:24 -07:00
Min-Yih Hsu
b363bbdd78 [IRGen][Patch 2/2] Add IRGen support for SIL DIExpression
This patch is primarily doing two things:
 - Teach IRGen for some of the instructions to generate debug info based
   on SILDebugVariable rather than AST node, which is not always
   available when reading from SIL.
 - Generate corresponding `llvm.dbg.*` intrinsics and `!DIExpression`
   from the newly added SIL DIExpression.
2021-07-21 09:26:51 -07:00
Hamish Knight
d4c25f55c2 [AST] Reject GenericFunctionType in TypeBase::getTypeOfMember
Remove the default argument for the `memberType`
parameter and enforce that GenericFunctionType is
not passed. Also add a defaulted overload for the
property case, as they should never have a
GenericFunctionType interface type.
2021-07-20 14:11:31 +01:00
Min-Yih Hsu
2d35d31290 [IRGen][DebugInfo] Use attached SILLocation for generating var debug loc
Currently IRGen requires the AST node of a variable declaration to
generate debug location. However, this will fail if the input is SIL due
to the lack of AST reconstruction. Plus, it's unnecessary since we can
just use the `SILLocation` attached on `debug_value` (and its friends) SIL
instruction to generate the correct LLVM debug metadata.

Resolves SR-14868
2021-07-06 09:40:53 -07:00
Min-Yih Hsu
8f3100a80b [IRGen] Correctly decode SILLocation w/ FilenameAndLocation storage
IRGen tried to decode various types of `SILLocation` into
`FilenameAndLocation` object. But it couldn't handle the case where
`SILLocation` already uses `FilenameAndLocationKind` storage kind. This
patch fixes this issue.

Resolves SR-14856
2021-06-29 14:29:05 -07:00
Adrian Prantl
946e8ef21c Fix a debug info regression introduced with async support.
This patch removes a heuristic to promote all debug intrinsics pointing into
allocas to llvm.dbg.declare() intrinsics and instead more accurate classifies
variables in async contexts by adding the missing cases alloc_box and
alloc_stack cases.

rdar://78977132
2021-06-09 11:42:45 -07:00
Adrian Prantl
3567b9f885 Refactor getSizeOfBasicType to take CompletedDebugTypeInfo (NFC)
(cherry picked from commit a5533fc056)
2021-05-24 17:38:58 -07:00
Adrian Prantl
57b1664f92 Debug Info: Distinguish between types of unknown size and types with size=0.
DebugInfoTypes didn't properly distinguish between types with an unknown size
and used 0 as the default value. This can cause types to show up in DWARF with a
size of 0, which will prevent LLDB from looking at the type further. In
practice, this meant that many resilient types (for example, SwiftUI Views)
couldn't be displayed in the debugger and just showed up as empty.

This patch does three things:

0. Make size in DebugTypeInfo optional.
1. Introduce CompletedDebugTypeInfo, a subclass of DebugTypeInfo where
   size is guaranteed to be non-empty.
2. Change some APIs that only make sense with a size to use
   CompletedDebugTypeInfo. This caused some churn because I needed to refactor
	 the get*Elements() functions back into their callers to facilitate the new
	 early-exit path. These functions are only called when compiling with
	 -gdwarf-types.
3. Change createOpaqueStructWithSizedContainer() to create a size-less forward
   declaration instead of a zero-sized type for the inner type.

rdar://76973844
(cherry picked from commit b8e6eebdbc)
2021-05-20 13:48:47 -07:00
Adrian Prantl
a6304c5168 Update the correct size of Builting.Executor, it is now 2 pointers.
Fixes an assertion while building the Concurrency module.
2021-04-30 17:08:35 -07:00
Azoy
9ed732f0ab Introduce isDecl and getDeclType
fix enum logic issue

fix tests

guard against null types
2021-04-20 02:22:16 -04:00
John McCall
0f152af85f Add a Builtin.Executor type to abstract executor references. 2021-03-28 04:31:49 -04:00