Commit Graph

1132 Commits

Author SHA1 Message Date
Nadav Rotem
07d4558c1c [Mangler] Change the Swift mangler into a symbol builder.
This commit changes the Swift mangler from a utility that writes tokens into a
stream into a name-builder that has two phases: "building a name", and "ready".
This clear separation is needed for the implementation of the compression layer.

Users of the mangler can continue to build the name using the mangleXXX methods,
but to access the results the users of the mangler need to call the finalize()
method. This method can write the result into a stream, like before, or return
an std::string.
2015-12-25 21:40:25 -08:00
Adrian Prantl
c44931ec1b Debug Info: Support generic function specialization by substituting
the archetype with the specialized type.

rdar://problem/21949734
2015-12-22 13:16:22 -08:00
practicalswift
cd7d8dfaff Fix alignment as requested by @gribozavr in #692 2015-12-21 08:54:24 +01:00
practicalswift
176f487d76 Fix incorrect filenames in headers. 2015-12-20 23:59:05 +01:00
practicalswift
8ab8847684 Fix typos. 2015-12-16 22:09:32 +01:00
Dmitri Gribenko
a50b8cd659 Merge pull request #510 from practicalswift/fix-typos-14
Fix typos (14 of 30)
2015-12-14 01:07:49 -08:00
practicalswift
3ba0c37236 Fix typo: guranteed → guaranteed 2015-12-14 00:11:49 +01:00
practicalswift
7705c30846 Fix typo: acually → actually 2015-12-13 23:56:39 +01:00
Adrian Prantl
3aec2c993f Debug Info: Fix the condition for detecting implicitly indirect types,
factor out the handling of implicitly indirect types
and add coverage for previouslt uncovered additional cases.

rdar://problem/23681035
2015-12-07 16:01:23 -08:00
Adrian Prantl
dd0db18ad4 Debug Info: Unify the handling of indirect values and fix a bug where
ParenTypes were not recognized as generic.

Fixes rdar://problem/23681035
2015-12-04 16:40:52 -08:00
Adrian Prantl
2e1c4fae7c Simplify the creation of DIExpressions. (NFC) 2015-12-04 16:40:52 -08:00
Adrian Prantl
0d300206cd Remove wrapper functions that added little value. (NFC) 2015-12-04 11:05:26 -08:00
Roger Z
741a31bf57 whitespace 2015-12-03 16:41:15 -05:00
Nadav Rotem
7dd34bf11f Fix an unused variable warning. 2015-12-01 09:41:50 -08:00
Adrian Prantl
8ab1e2dd50 Unify debug scope and location handling in SILInstruction and SILBuilder.
The drivers for this change are providing a simpler API to SIL pass
authors, having a more efficient of the in-memory representation,
and ruling out an entire class of common bugs that usually result
in hard-to-debug backend crashes.

Summary
-------

SILInstruction

Old                   New
+---------------+     +------------------+    +-----------------+
|SILInstruction |     |SILInstruction    |    |SILDebugLocation |
+---------------+     +------------------+    +-----------------+
| ...           |     | ...              |    | ...             |
|SILLocation    |     |SILDebugLocation *| -> |SILLocation      |
|SILDebugScope *|     +------------------+    |SILDebugScope *  |
+---------------+                             +-----------------+

We’re introducing a new class SILDebugLocation which represents the
combination of a SILLocation and a SILDebugScope.
Instead of storing an inline SILLocation and a SILDebugScope pointer,
SILInstruction now only has one SILDebugLocation pointer. The APIs of
SILBuilder and SILDebugLocation guarantees that every SILInstruction
has a nonempty SILDebugScope.

Developer-visible changes include:

SILBuilder
----------

In the old design SILBuilder populated the InsertedInstrs list to
allow setting the debug scopes of all built instructions in bulk
at the very end (as the responsibility of the user). In the new design,
SILBuilder now carries a "current debug scope" state and immediately
sets the debug scope when an instruction is inserted.
This fixes a use-after-free issue with with SIL passes that delete
instructions before destroying the SILBuilder that created them.

Because of this, SILBuilderWithScopes no longer needs to be a template,
which simplifies its call sites.

SILInstruction
--------------

It is neither possible or necessary to manually call setDebugScope()
on a SILInstruction any more. The function still exists as a private
method, but is only used when splicing instructions from one function
to another.

Efficiency
----------

In addition to dropping 20 bytes from each SILInstruction,
SILDebugLocations are now allocated in the SILModule's bump pointer
allocator and are uniqued by SILBuilder. Unfortunately repeat compiles
of the standard library already vary by about 5% so I couldn’t yet
produce reliable numbers for how much this saves overall.

rdar://problem/22017421
2015-11-19 09:31:26 -08:00
Adrian Prantl
551b0c8e02 Adapt to upstream LLVM API changes. 2015-11-11 16:07:41 -08:00
Adrian Prantl
fa32b72806 Debug Info: Establish a default ordering for compile units.
Because the swift compiler relies on Clang to setup the Module,
the clang CU is always created first.  Several dwarf-reading
tools (older versions of ld64, and lldb) can get confused if the
first CU in an object is empty, so ensure that the Swift CU comes
first by rearranging the list of CUs in the LLVM module.

rdar://problem/23434643
2015-11-06 15:49:44 -08:00
Adrian Prantl
2f9f964219 Change the contract between Swift compiler and LLDB about how the function
prologue is handled in the line table.
We now mark the first instruction after the stack setup as end_prologue and
any further initilizations (which may include function calls to metadata
accessors) with line 0 which lldb will skip. This allows swiftc to emit
debug info for compiler-generated functions such as metadata accessors.
Mixing debug and non-debug functions is not very well supported by LLVM
and the resulting line table makes it impossible for LLDB to determine
where a function with debug info ends and a nondebug function starts.

rdar://problem/23042642

Swift SVN r32816
2015-10-22 00:20:03 +00:00
Michael Gottesman
8d60988e51 Update IRGenDebugInfo for upstream API change.
Swift SVN r32809
2015-10-21 21:45:21 +00:00
Adrian Prantl
c2f66872d1 Don't take the address of a temporary. NFC.
Swift SVN r32638
2015-10-12 22:42:15 +00:00
Adrian Prantl
3356f7ac59 Pass the debug info settings through to Clang and ensure that compile units
created by Swift and Clang set the CU's compilation dir similarly.

rdar://problem/22692266

Swift SVN r32637
2015-10-12 22:20:58 +00:00
Michael Gottesman
f1967716b6 Adapt IRGenDebugInfo::emitVariableDeclaration() to new LLVM API.
Swift SVN r31803
2015-09-09 04:37:20 +00:00
Michael Gottesman
0606d5843a Remove calls to raw_svector_ostream::flush()
This function is deleted since LLVM r244928.

Swift SVN r31798
2015-09-09 04:37:13 +00:00
Jordan Rose
cb2c6a6d08 Demangle 'So' as '__ObjC' rather than 'ObjectiveC'.
And similarly 'SC' as '__C' rather than 'C'.

There's a real module named 'ObjectiveC', and imported decls are not
all in it.

Swift SVN r31225
2015-08-13 21:22:02 +00:00
Chris Lattner
a899872d91 Reapply r31105, with some fixes to invalid unconstrained generics. These fixes correct
the regressions that r31105 introduced in the validation tests, as well as fixing a number
of other validation tests as well.

Introduce a new UnresolvedType to the type system, and have CSDiags start to use it
as a way to get more type information out of incorrect subexpressions.  UnresolvedType
generally just propagates around the type system like a type variable:
 - it magically conforms to all protocols
 - it CSGens as an unconstrained type variable.
 - it ASTPrints as _, just like a type variable.

The major difference is that UnresolvedType can be used outside the context of a
ConstraintSystem, which is useful for CSGen since it sets up several of them to 
diagnose subexpressions w.r.t. their types.

For now, our use of this is extremely limited: when a closureexpr has no contextual
type available and its parameters are invalid, we wipe them out with UnresolvedType
(instead of the previous nulltype dance) to get ambiguities later on.

We also introduce a new FreeTypeVariableBinding::UnresolvedType approach for
constraint solving (and use this only in one place in CSDiags so far, to resolve
the callee of a CallExpr) which solves a system and rewrites any leftover type 
variables as UnresolvedTypes.  This allows us to get more precise information out,
for example, diagnosing:

 func r22162441(lines: [String]) {
   lines.map { line in line.fooBar() }
 }

with: value of type 'String' has no member 'fooBar'
instead of: type of expression is ambiguous without more context

This improves a number of other diagnostics as well, but is just the infrastructural
stepping stone for greater things.





Swift SVN r31130
2015-08-11 06:06:05 +00:00
Chris Lattner
2204dbcbfd revert r31105, it causes some regressions on validation tests.
Swift SVN r31107
2015-08-10 15:01:22 +00:00
Chris Lattner
de79b60c89 Introduce a new UnresolvedType to the type system, and have CSDiags start to use it
as a way to get more type information out of incorrect subexpressions.  UnresolvedType
generally just propagates around the type system like a type variable:
 - it magically conforms to all protocols
 - it CSGens as an unconstrained type variable.
 - it ASTPrints as _, just like a type variable.

The major difference is that UnresolvedType can be used outside the context of a
ConstraintSystem, which is useful for CSGen since it sets up several of them to 
diagnose subexpressions w.r.t. their types.

For now, our use of this is extremely limited: when a closureexpr has no contextual
type available and its parameters are invalid, we wipe them out with UnresolvedType
(instead of the previous nulltype dance) to get ambiguities later on.

We also introduce a new FreeTypeVariableBinding::UnresolvedType approach for
constraint solving (and use this only in one place in CSDiags so far, to resolve
the callee of a CallExpr) which solves a system and rewrites any leftover type 
variables as UnresolvedTypes.  This allows us to get more precise information out,
for example, diagnosing:

 func r22162441(lines: [String]) {
   lines.map { line in line.fooBar() }
 }

with: value of type 'String' has no member 'fooBar'
instead of: type of expression is ambiguous without more context

This improves a number of other diagnostics as well, but is just the infrastructural
stepping stone for greater things.



Swift SVN r31105
2015-08-10 06:18:27 +00:00
Frederic Riss
f3816e6dfa DebugInfo: Do not infinite loop on indirect enums.
When computing the locations for local indirect enums, we could enter
an infinite loop if the first field is a recursive reference.
Just bail out of the field-splitting logic if we encounter an indirect
case. More work might be needed if indirect enums get exploded.

rdar://problem/21927941

Swift SVN r30717
2015-07-28 17:18:02 +00:00
Slava Pestov
e748908990 Sema: Don't set type of TypeAliasDecl until we resolve the alias type
This changes the behavior to match NominalTypeDecls, which don't have a type
until everything is set up either. In a few places we construct TypeAliasDecls
from known types directly, and we have to call computeType().

Fixes <rdar://problem/19534837>.

Swift SVN r30386
2015-07-19 20:55:53 +00:00
Adrian Prantl
c5dd8bea82 Debug Info: Migrate from MDModule to DIModule.
MDModule was a bitcode-incompatible internal-only extension that has
since been replaced with a blessed IR node on trunk.

<rdar://problem/20965932> Upstream DIModule and support it in clang-700, swiftlang-700, and lldb-700

Swift SVN r29832
2015-07-01 02:25:22 +00:00
Dmitri Hrybenko
2fc1cbe8c1 Adjust to the new IRBuilder APIs
Swift SVN r29692
2015-06-25 22:01:24 +00:00
Adrian Prantl
462fb4b74d Remove an overly strict assertion.
<rdar://problem/21462005>

Swift SVN r29531
2015-06-20 00:03:20 +00:00
Adrian Prantl
cc74abe0f5 Remove a redundant assertion.
Swift SVN r29530
2015-06-20 00:03:18 +00:00
Joe Groff
e57c470019 Introduce a "@box T" type for SIL.
Represents a heap allocation containing a value of type T, which we'll be able to use to represent the payloads of indirect enum cases, and also improve codegen of current boxes, which generates non-uniqued box metadata on every allocation, which is dumb. No codegen changes or IRGen support yet; that will come later.

This time, fix a paste-o that caused SILBlockStorageTypes to get replaced with SILBoxTypes during type substitution. Oops.

Swift SVN r29489
2015-06-18 15:21:52 +00:00
Mark Lacey
39087cd36b Revert "Introduce a "@box T" type for SIL."
This reverts commit r29474 because it looks like it is breaking the
build of the SpriteKit overlay.

Swift SVN r29482
2015-06-18 06:28:04 +00:00
Joe Groff
7b0045c790 Introduce a "@box T" type for SIL.
Represents a heap allocation containing a value of type T, which we'll be able to use to represent the payloads of indirect enum cases, and also improve codegen of current boxes, which generates non-uniqued box metadata on every allocation, which is dumb. No codegen changes or IRGen support yet; that will come later.

Swift SVN r29474
2015-06-18 04:07:03 +00:00
Adrian Prantl
96cc406c7d Debug Info: Ensure classes report their storage size correctly
by wrapping them in a pointer-sized struct as we do for all things passed
by reference.

Fixes rdar://21409965

Swift SVN r29455
2015-06-17 18:19:00 +00:00
Adrian Prantl
e91b59ff79 Debug Info: Also treat tuple types like all other composite types and
create a replaceable forward declaration while building it.
This fixes a crash when building generic enums a tuple element recursively
referenceing the enum.

rdar://problem/21326786

Swift SVN r29416
2015-06-17 00:36:05 +00:00
Adrian Prantl
44f78857f3 Debug Info: Treat subroutine types like all other composite types
and create a replaceable forward declaration while building it.
This fixes a crash when building generic enums with a constructor
function.

<rdar://problem/21294835>

Swift SVN r29411
2015-06-16 23:29:26 +00:00
Adrian Prantl
ab4467dc03 Debug Info: Set the mangled name for temporary composite types
and use DIBuilder::replaceTemporary() to RAUW temporary debug nodes.
This enables more opportunities for IR debug type uniquing.

Swift SVN r29410
2015-06-16 23:29:22 +00:00
Adrian Prantl
767a57bef7 Debug Info: Ensure that an alloca is described by exactly one
dbg.declare.

Caught by an assertion in LLVM.

Swift SVN r29192
2015-05-31 17:38:33 +00:00
Adrian Prantl
1daaf310fb Revert "Reverting commits 29181-29187 to investigate buildbot breakage."
This reverts commit 29189.

Swift SVN r29191
2015-05-31 17:38:32 +00:00
Adrian Prantl
b994bde5b5 Reverting commits 29181-29187 to investigate buildbot breakage.
Swift SVN r29190
2015-05-31 06:13:03 +00:00
Adrian Prantl
a17e6390e7 Debug Info: Unique Archetypes.
With all the previous bugfixes it is no longer necessary to keep separate
copies because inlining and generic specialization is now handled
correctly so each specialized variable has its own specialized version
of the archetype.

rdar://problem/21109015

Swift SVN r29187
2015-05-31 05:39:32 +00:00
Adrian Prantl
c08207e811 Debug Info: Don't emit dbg.declares for SIL-optimized code.
A dbg.declare is only meaningful if there is a single alloca for
the variable that is live throughout the function. With SIL
optimizations this is not guranteed and a variable can end up in
two allocas (for example, one function inlined twice).

Caught by an assertion in LLVM.

rdar://problem/21109015

Swift SVN r29186
2015-05-31 05:39:31 +00:00
Adrian Prantl
7c4de1ff3c Debug Info: Do not keep abstract variables until we can actually unique
them.

Caught by an assertion in LLVM.
rdar://problem/21109015

Swift SVN r29185
2015-05-31 05:39:31 +00:00
Erik Eckstein
daaea3705f Fix a debug-info bug in multi-threaded compilation mode.
The compilation-unit's filename was not set correctly. This led to warnings printed by dsymutil.
There is no radar for this problem.



Swift SVN r28424
2015-05-11 18:12:10 +00:00
Adrian Prantl
acba19a494 Debug Info: Remove an early exit that prevented the swift frontend from
emitting indirect pieces — LLVM (ToT, 700) now supports this.

Since this only happens in optimized code it is currently not feasible
to write a non-flaky testcase for this. I'll revisit this once our
SIL serialization efforts progressed further.

<rdar://problem/19427586> Support indirect pieces

Swift SVN r28051
2015-05-01 22:13:01 +00:00
Adrian Prantl
fa402df22d Debug Info: Anonymous functions should only have a linkage name.
<rdar://problem/20008393> MDSubprogram has name

Swift SVN r27981
2015-04-30 16:30:15 +00:00
Duncan Exon Smith
c6d42db070 Adapt to MD* => DI* renaming of debug info types
Applied the upgrade script from r236120 (LLVM) and r236121 (CFE).  This is the
final step of rdar://problem/20434113.



Swift SVN r27925
2015-04-29 21:40:21 +00:00