Commit Graph

519 Commits

Author SHA1 Message Date
Michael Gottesman
7e39f33f98 [mangle] Include a pass id in the mangling, just to be careful.
I am starting to reuse manglings for different passes. I want to make sure that
when we reuse functions we actually get a function created by the same pass.

Swift SVN r23924
2014-12-14 10:29:11 +00:00
Michael Gottesman
45b5389854 [mangle] Add support for mangling CapturePromotion specializations and wire it up.
<rdar://problem/19216281>

Swift SVN r23923
2014-12-14 08:17:32 +00:00
Michael Gottesman
c4f3043280 [mangle] Specify sizes for various specialization enums and make the underlying type configurable via a using statement.
Also added comments about how various parts of the enum are
used (i.e. options vs option sets).

Swift SVN r23922
2014-12-14 08:17:31 +00:00
Michael Gottesman
1e63e0e22d [mangle] Add support for mangling dead, owned2guaranteed, and sroa args. Wire up function sig opts.
Now all SIL function specialization passes use the new mangling infrastructure.
Lets keep it that way for future passes as well. = ).

Implements:
<rdar://problem/18831609>

Fixes:
<rdar://problem/19065735>
<rdar://problem/18906781>
<rdar://problem/18956916>

Swift SVN r23859
2014-12-11 05:51:26 +00:00
Michael Gottesman
185d9aaafd [mangle] Add support for mangling constant propagated specializations and wire CapturePropagation to use it.
I also fixed a few bugs in the mangling that this exposed.

Swift SVN r23858
2014-12-11 03:22:07 +00:00
Michael Gottesman
355f791621 [mangle] Add support for function signature specialization mangling and teach closure specialization how to use it.
Swift SVN r23816
2014-12-09 23:21:08 +00:00
Michael Gottesman
4d48d2aaae [mangle] Add initial code for SIL specializations manglings and refactor Generic Specialization mangling code to there from the pass itself.
This is apart of creating the infrastructure for creating special manglings for
all of the passes that we specialize. The main motiviations for this
infrastructure is:

1. Create an easy method with examples on how to create these manglings.
2. Support multiple specializations. This is important once we allow for partial
specialization and can already occur if we perform function signature
optimizations on specialized functions.

The overall scheme is as follows:

_TTS<MANGLINGINFO>__<FUNCNAME>

Thus if we specialize twice, the first specialization will just be treated as
the function name for the second specialization.

<MANGLINGINFO> is defined as:

_<SPECIALIZATIONKINDID>_<SPECIALIZATIONUNIQUEINFO>

Where specialization kind is an enum that specifies the specific sort of
specialization we are performing and specialization unique info is enough
information to ensure that the identity of the function is appropriately
preserved.

Swift SVN r23801
2014-12-09 02:53:05 +00:00
Dmitri Hrybenko
f6e926224e Fix warnings about unused variables when assertions are turned off
Swift SVN r23641
2014-12-03 04:48:38 +00:00
Joe Groff
08fe138808 Runtime: Generate a human-understandable name for Any.Type.
Expose this in the stdlib as _typeName(Any.Type) -> String, pending API review.

Swift SVN r23254
2014-11-11 23:38:24 +00:00
Dmitri Hrybenko
be90da8181 CMake: allow specifying Swift compiler flags separately from C compiler flags
Swift SVN r23174
2014-11-08 04:41:07 +00:00
Manman Ren
276af26e12 [Global Opt] adds GlobalGetter as one kind of SILDeclRef.
Also handles mangling, demangling, printing and parsing.

This is the first patch to use global getter for "let" globals.

rdar://16614767


Swift SVN r23106
2014-11-05 00:40:32 +00:00
Joe Groff
0bafa4d05b Restore the module context and generic parameter list to protocol conformance mangling.
We don't need to game the mangling to be easily predictable by conformsToProtocol anymore.

Swift SVN r23089
2014-11-03 21:56:54 +00:00
Adrian Prantl
801dc3d20e Debug info: Actually encode the Swift version number instead of constant 1.
<rdar://problem/18729762> CU's RuntimeVersion field should have the Swift runtime version number

Swift SVN r23087
2014-11-03 17:48:06 +00:00
Joe Groff
5a2f48e3be Add a Builtin.BridgeObject type.
This is a type that has ownership of a reference while allowing access to the
spare bits inside the pointer, but which can also safely hold an ObjC tagged pointer
reference (with no spare bits of course). It additionally blesses one
Foundation-coordinated bit with the meaning of "has swift refcounting" in order
to get a faster short-circuit to native refcounting. It supports the following
builtin operations:

- Builtin.castToBridgeObject<T>(ref: T, bits: Builtin.Word) ->
  Builtin.BridgeObject

  Creates a BridgeObject that contains the bitwise-OR of the bit patterns of
  "ref" and "bits". It is the user's responsibility to ensure "bits" doesn't
  interfere with the reference identity of the resulting value. In other words,
  it is undefined behavior unless:

    castReferenceFromBridgeObject(castToBridgeObject(ref, bits)) === ref

  This means "bits" must be zero if "ref" is a tagged pointer. If "ref" is a real
  object pointer, "bits" must not have any non-spare bits set (unless they're
  already set in the pointer value). The native discriminator bit may only be set
  if the object is Swift-refcounted.

- Builtin.castReferenceFromBridgeObject<T>(bo: Builtin.BridgeObject) -> T

  Extracts the reference from a BridgeObject.

- Builtin.castBitPatternFromBridgeObject(bo: Builtin.BridgeObject) -> Builtin.Word

  Presents the bit pattern of a BridgeObject as a Word.

BridgeObject's bits are set up as follows on the various platforms:

i386, armv7:

  No ObjC tagged pointers
  Swift native refcounting flag bit: 0x0000_0001
  Other available spare bits:        0x0000_0002

x86_64:

  Reserved for ObjC tagged pointers: 0x8000_0000_0000_0001
  Swift native refcounting flag bit: 0x0000_0000_0000_0002
  Other available spare bits:        0x7F00_0000_0000_0004

arm64:

  Reserved for ObjC tagged pointers: 0x8000_0000_0000_0000
  Swift native refcounting flag bit: 0x4000_0000_0000_0000
  Other available spare bits:        0x3F00_0000_0000_0007

TODO: BridgeObject doesn't present any extra inhabitants. It ought to at least provide null as an extra inhabitant for Optional.

Swift SVN r22880
2014-10-23 00:09:23 +00:00
Dmitri Hrybenko
8fa7112760 Fix 80-column violation
Swift SVN r22551
2014-10-06 21:01:22 +00:00
Jordan Rose
3fcdfd40e9 Remove the "swift/Basic/Optional.h" header.
llvm::Optional lives in "llvm/ADT/Optional.h". Like Clang, we can get
Optional in the 'swift' namespace by including "swift/Basic/LLVM.h".

We're now fully switched over to llvm::Optional!

Swift SVN r22477
2014-10-02 18:51:45 +00:00
Jordan Rose
042569a3be Optional: Replace uses of Nothing with None.
llvm::Optional (like Swift.Optional!) uses None as its placeholder value,
not Nothing.

Swift SVN r22476
2014-10-02 18:51:42 +00:00
Graham Batty
d269d5c656 Basic: Add dependency finding for libuuid.
Swift SVN r22434
2014-10-01 19:05:46 +00:00
Dmitri Hrybenko
dad84989e3 Don't assume 'uuid_string_t' type is defined
It is not defined on Linux.

Swift SVN r22413
2014-09-30 22:37:42 +00:00
Joe Groff
ff8d6411c0 Push uuid system dependencies out of header.
Swift SVN r22412
2014-09-30 22:32:57 +00:00
Dmitri Hrybenko
97b166fe8a Fix a warning about redundant comparison of unsigned char to 0
Swift SVN r22340
2014-09-28 18:56:59 +00:00
Dmitri Hrybenko
fe39104a5a Include headers required for waitpid()
Swift SVN r22323
2014-09-28 01:38:26 +00:00
Dmitri Hrybenko
8fdd6aca87 Fix warnings about falling off the end of a function without a return
Swift SVN r22317
2014-09-27 23:34:22 +00:00
John McCall
671613644d Demangling support for mutableAddressor.
Note that the demangling for 'a' accessors changes from
'addressor' to 'mutableAddressor'.  This is correct for
the existing use-case of global variables, which permit
modification through the result.

Swift SVN r22254
2014-09-24 04:19:30 +00:00
Joe Groff
2f2a9ba30f Demangle: Preserve generic contexts after generic types have been demangled.
They may be backreferenced by contexts nested inside the generic context, namely closures. Fixes the remainder of rdar://problem/18306777.

Swift SVN r22041
2014-09-17 21:17:58 +00:00
Joe Groff
0add2f32b2 Remove dead method.
Swift SVN r22040
2014-09-17 21:17:57 +00:00
John McCall
75050f8166 Generate an implicit 'materializeForSet' accessor
along with getters and setters.

Just generate it for now.

Swift SVN r22011
2014-09-17 08:08:03 +00:00
Joe Groff
c864101f05 Demangle: Fix demangling of existential metatypes.
Handles several of the cases in rdar://problem/18306777.

Swift SVN r22002
2014-09-17 03:57:30 +00:00
Jordan Rose
ff59af1e69 Only test that all SourceManager buffers are valid when actually still valid.
Some of the buffers are owned by the ClangImporter, so after the
ClangImporter's been deallocated, the SourceManager isn't going to be fully
valid any more.

Should fix issues from r21958.

Swift SVN r21989
2014-09-16 22:41:27 +00:00
Jordan Rose
3d3c6fa730 [ClangImporter] Fix crash when a diagnostic is reported during module building.
This rare crash happens when
1. A diagnostic is reported when building a Clang module.
2. The diagnostic is mapped to a Swift diagnostic by mirroring the Clang
   source buffer as a Swift source buffer (via non-owning reference).
3. The Clang CompilerInstance used specifically to build the module is
   destroyed.
4. Some /new/ buffer is allocated in the same memory spot as the old buffer.
5. Some new Clang diagnostic occurs in the new buffer.
6. The Swift source manager asserts when trying to set up a virtual name
   for the diagnostic in the second imported buffer, because there's already
   a name for that region.

The fix, because we don't expect diagnostics from modules to appear very
often, is to keep any clang::SourceManagers alive if diagnostics are emitted
in their buffers. We can revisit this if/when Swift's source manager
(currently built on llvm::SourceMgr) has the ability to remove buffers.

Many thanks to Greg for noticing the problem, tracking it down, and providing
a diff to make it fail reproducibly under GuardMalloc. I've tried to preserve
the spirit of that diff in the new logic in ~SourceManager, which will also
fail reliably with GuardMalloc (and probably ASan).

rdar://problem/18285805

Swift SVN r21958
2014-09-15 22:26:48 +00:00
Jordan Rose
6851d95735 Defensive commit: avoid pointer use-after-invalidation.
I don't /think/ we can get into this state but it's better to be safe.

Swift SVN r21900
2014-09-12 02:54:47 +00:00
Connor Wakamo
725f501e9b Fixed the escaping of strings in swift::json::Output.
Instead of using llvm::raw_ostream::write_escaped (which does not produce valid
JSON strings), implemented custom escaping logic based on the JSON standard,
which only requires that the following characters be escaped:

  - Quotation mark (U+0022)
  - Reverse solidus (U+005C)
  - Control characters (U+0000 to U+001F)

Since these characters all fit within a single UTF8 byte, and will not be
present in a multi-byte UTF8 representation, simply check whether the current
byte needs to be escaped according to those requirements. If the current byte
needs to be escaped, then print out the escaped version of the byte; otherwise,
pass the current byte to the stream directly.

This fixes <rdar://problem/18266570>.

Swift SVN r21892
2014-09-11 22:20:05 +00:00
Ted Kremenek
ff5f742c68 Update Swift version to '1.1'. This includes bumping the Swift
ABI version to '2'.

This patch shows that we need to consolidate where we encode
version information in our CMake build; that's for a later patch.

Implements rdar://problem/18238390.

Swift SVN r21850
2014-09-10 20:49:59 +00:00
Jordan Rose
47658c87eb Start mangling names of private declarations specially.
We currently mangle private declarations exactly like public declarations,
which means that private entities with the same name and same type will
have the same symbol even if defined in separate files.

This commit introduces a new mangling production, private-decl-name, which
includes a discriminator string to identify the file a decl came from.
Actually producing a unique string has not yet been implemented, nor
serialization, nor lookup using such a discriminator.

Part of rdar://problem/17632175.

Swift SVN r21598
2014-08-30 00:17:18 +00:00
Roman Levenstein
97014172b7 [sil-combine] String literal concatenation optimization. Constant-fold concatenation of string literals known at compile-time.
Addresses rdar://17033696.

Swift SVN r21526
2014-08-28 11:33:21 +00:00
Manman Ren
2cb20d4e62 [Mangler] mangle the module where an extension is defined if necessary.
If a method is defined within an extension of a class or struct that is
defined in a different module, we mangle the module where the extension is
defined.

If we define function f in module A, and redefine it again in an extension in
module B, we use different mangling to prevent linking in the wrong
SILFunction.

rdar://18057875


Swift SVN r21488
2014-08-27 19:57:21 +00:00
Dmitri Hrybenko
42b25d939d Update for upstream LLVM changes is MemoryBuffer APIs
Swift SVN r21409
2014-08-22 08:28:03 +00:00
Manman Ren
31dc9957bf [Print QuotedString] print \u{..} instead of \x.
The lexer can't handle "\x08". QuotedString currently is only used in ASTDumper,
SILPrinter and PrettyStackTrace, so changing the print function should not break
other things.

rdar://18020704


Swift SVN r21257
2014-08-18 17:53:20 +00:00
Dmitri Hrybenko
938e7c2676 stdlib: introduce UnicodeScalarLiteralConvertible protocol
This allows UnicodeScalars to be constructed from an integer, rather
then from a string.  Not only this avoids an unnecessary memory
allocation (!) when creating a UnicodeScalar, this also allows the
compiler to statically check that the string contains a single scalar
value (in the same way the compiler checks that Character contains only
a single extended grapheme cluster).

rdar://17966622

Swift SVN r21198
2014-08-14 16:04:39 +00:00
Joe Groff
fb4fe43e3b Handle '?' as an operator character in mangling.
Alphabetize it like the other operator characters are mangled.

Swift SVN r21062
2014-08-06 05:27:29 +00:00
Jordan Rose
43cbe397fb Fix SourceManager::closeVirtualFile when the end loc is the buffer end.
Previously it crashed; now it (correctly) does nothing.

<rdar://problem/17887975>

Swift SVN r20921
2014-08-01 21:56:19 +00:00
Connor Wakamo
a69eb17411 [json] Added a basic JSON serialization class in swiftBasic.
The swift::json namespace now contains an Output class, which largely mirrors
llvm::yaml::Output. It takes the same approach where there are various traits
structs which dictate how a particular type is output in JSON. (This is separate
from llvm::yaml because, while all JSON is valid YAML, not all YAML is valid
JSON, and customization on how scalar types are output as JSON is necessary.)

Unlike llvm::yaml, there is no equivalent Input class. Since JSON is valid YAML,
llvm::yaml::Input can be used instead.

At some point, the traits structs could likely be merged with llvm::yaml (with
some ability to customize how scalars are output if it's outputting JSON instead
of YAML), but this provides enough of a starting point to allow the driver to
generate parseable output in JSON format.

Part of <rdar://problem/15958329>.

Swift SVN r20870
2014-08-01 01:15:35 +00:00
Connor Wakamo
93f7f2ad43 [driver] Fixed a bug in DummyTaskQueue where it would not generate unique ProcessIds.
Since DummyTaskQueue does not actually execute, it keeps a counter of
ProcessIds. This previously was a local variable; it is now static since
multiple instances of DummyTaskQueue may be used, depending on the requested
commands.

No tests for this yet, but this will be required to properly test parseable
output.

Swift SVN r20849
2014-07-31 21:19:57 +00:00
John McCall
584795e505 Replace the typeOf value witness with an
initializeBufferWithTakeOfBuffer value witness.

Attempt to use initializeBufferWithTakeOfBuffer in
some appropriate places.

There are some changes enabled by this which are
coming in a follow-up patch.

Swift SVN r20741
2014-07-30 08:24:12 +00:00
Jordan Rose
0b933acfda [ClangImporter] Use #line when reporting module build errors.
...or at least the same machinery as #line. We add a (referential) mirror
of the Clang buffer to Swift's source manager, then remap that particular
line to whatever Clang currently thinks is the presumed location for that
line. (This means we respect Clang line directives too.)

This also modifies Swift's source manager to be more forgiving about adding
the same virtual file range twice; it will tell you when you try to do it.

<rdar://problem/16596800>

Swift SVN r20572
2014-07-25 23:01:45 +00:00
Jordan Rose
29f8c25d63 Move #line state into the Parser and out of the SourceManager.
As part of this change, allow #line directives to extend to the end of the
file, rather than requiring a reset.

Note that #line regions that start or end within function bodies will not
behave correctly when in delayed parsing modes. This was true before and
after this commit. (#line regions contained entirely within a function and
not within any other #line regions should be fine.)

Swift SVN r20571
2014-07-25 23:01:43 +00:00
John McCall
1ae1f750d0 Move most type metadata lookups into their own readnone
functions, and make those functions memoize the result.

This memoization can be both threadsafe and extremely
fast because of the memory ordering rules of the platforms
we're targeting: x86 is very permissive, and ARM has a
very convenient address-dependence rule which happens to
exactly match the semantics we need.

Swift SVN r20381
2014-07-23 07:38:26 +00:00
Dmitri Hrybenko
df21376444 Punycode: implement a UTF-8 encoder for use in demangler
Swift SVN r20311
2014-07-22 15:37:45 +00:00
Dmitri Hrybenko
e7b4e6c370 Punycode encoder/decoder: separate core and parts that depend on UTF8
encoder/decoder


Swift SVN r20309
2014-07-22 15:01:12 +00:00
Dmitri Hrybenko
734c0a9ba1 Revert "Punycode encoder/decoder: separate core and parts that depend on UTF8"
It broke tests.

Swift SVN r20308
2014-07-22 14:44:20 +00:00