Commit Graph

9268 Commits

Author SHA1 Message Date
Chris Lattner
dd3e962698 sink some more logic down to GenericTypeDecl, add support for safe downcasting
from Decl to GenericTypeDecl.  NFC.
2016-03-06 21:44:40 -08:00
practicalswift
50f8abe6f5 Merge pull request #1555 from kevinwcyu/fix-typos-whitespaces
[gardening] Fix typos "cant" → "can't", "dont" → "don't".
2016-03-06 20:18:18 +01:00
Kevin Yu
8f193c856e [gardening] Fix typos "cant" -> "can't", "dont" -> "don't" 2016-03-06 00:25:14 +00:00
Xi Ge
40f0c7c1f3 ModulePrinting: Save some copies by passing function pointer. NFC 2016-03-05 12:29:01 -08:00
Chris Lattner
868a795566 Introduce a new class between TypeDecl and NominalTypeDecl named GenericTypeDecl.
This factors the DeclContext and generic signature behavior out of NTD, allowing
it to be reused in the future.  NFC.
2016-03-04 23:09:15 -08:00
David Farler
bd6d657411 Get typerefs for existential type metadata 2016-03-04 17:10:40 -08:00
David Farler
0f05b390c3 Gardening: fix some 80-column violations 2016-03-04 17:10:40 -08:00
David Farler
3b2ceb7f19 Skip name= header if ObjCClass/Foreign TypeRef name is empty
A minor cosmetic change when dumping typerefs.
2016-03-04 17:10:40 -08:00
David Farler
5f169b466c Get typerefs for function type metadata 2016-03-04 17:10:40 -08:00
David Farler
04444c44a2 Get typerefs for tuple type metadata, including their elements 2016-03-04 17:10:40 -08:00
David Farler
5196f5b89c Get typerefs for nominal type metadata
and read their generic arguments, if there are any, too.
2016-03-04 17:10:39 -08:00
Ben Langmuir
5c29920acd [ASTPrinter] Simplify callbacks by dropping the notion of 'pending' callbacks
The three varieties of 'pending callbacks' made it hard to reason about
how callbacks would be presented to subclasses of ASTPrinter.  I
recently added new callbacks that would have made this even more complex
to deal with.

Luckily, it turns out they weren't buying us much, and simply forcing
any pending newlines and indentation to be printed ahead of making
callbacks was almost identical to the old behaviour. One complication is
that we now need to check for clang doc comments up front so we will
emit a newline in the right place.

This also incidentally fixed a bug in Loc vs Decl callback order.
2016-03-04 16:26:35 -08:00
Chris Lattner
9e62009bb6 update comment for "new" syntax, NFC. 2016-03-04 16:00:37 -08:00
Ben Langmuir
0af56408f9 Merge pull request #1539 from naoyashiga/typo-fixes-gray
[gardening] Fix recently introduced typo: "grey" → "gray"
2016-03-04 15:28:40 -08:00
Ben Langmuir
8e8a0ef6db Hide some comments from -Wdocumentation to shut up warnings
Clang doesn't seem to treat variables of function pointer type as valid
functions (unlike e.g. typedefs of function types), so it was warning
about \param and \returns.  For now, just disable the warning in this
header.  I filed rdar://problem/24978538 to fix clang.
2016-03-04 10:52:23 -08:00
naoyashiga
803bb1ba54 fix typo 2016-03-04 22:14:38 +09:00
practicalswift
5b2800225d [gardening] Fix recently introduced typos
Fixed:
* perfomance → performance
* requirments → requirements
* satisified → satisfied
* template template → template
2016-03-04 11:10:50 +01:00
Ben Langmuir
1ea2d46a04 [SourceKit] Add builtin attribute tags
As promised, tag the whole attribute include all of its 'parameters'.

rdar://problem/24292226
2016-03-03 21:20:14 -08:00
Ben Langmuir
bb152f14f9 [ASTPrinter] Fix decl/structure nested callbacks
For now, just force any pending callbacks before doing the structure
callbacks.  This should be fine, since we are always about to print
*something* that isn't whitespace, so there is no change in location.
2016-03-03 20:54:12 -08:00
Ben Langmuir
ba702b846f [SourceKit] Add tags for attribute names
As a first foray into annotating attribute, add tags around attribute
names. For now, treat any decl-modifiers as keywords. We will also want
to wrap the whole attribute (including any parameters) into tags as
well, but that will require more work in the callback hanlding.

Also factor the attribute printing to handle any special cases early,
which will simplify wrapping attributes in tags, since we can then just
put the whole switch intside the pre/post callbacks.

rdar://problem/24292226
2016-03-03 18:39:21 -08:00
Ben Langmuir
f61a241dfc [ASTPrinter] Rename parameter callback to widen scope NFC
I want to start using this for other things like function types and
attributes, so rename it to reflect the new scope. I'm not really happy
with "PrintStructureKind", etc. but haven't come up with anything
better so far.
2016-03-03 18:39:20 -08:00
Xi Ge
591249f953 Simplify some code. NFC 2016-03-03 18:25:35 -08:00
Xi Ge
8bde763ba2 IDETypeChecking: make parameter consistently pass reference. NFC 2016-03-03 18:02:13 -08:00
Xi Ge
326514e397 ModulePrinting: when printing synthesized extensions, avoid printing requirements that are known to be true. 2016-03-03 17:42:35 -08:00
Chris Lattner
d197cc5022 Merge pull request #1531 from practicalswift/fix-headers
[gardening] Fix recently introduced file headers. Also: "–" → "--".
2016-03-03 16:18:10 -08:00
Ben Langmuir
65f0e7eb94 [SourceKit] Add annotation tags for generic type requirements
Each requirement gets tagged. We could also tag the whole where clause
if we need to, but so far it hasn't been interesting.

rdar://problem/24292226
2016-03-03 16:11:07 -08:00
Joe Groff
be71ab28e2 SIL: Add an MarkUninitializedBehavior instruction for behavior DI.
This instruction creates a "virtual" address to represent a property with a behavior that supports definite initialization. The instruction holds references to functions that perform the initialization and 'set' logic for the property. It will be DI's job to rewrite assignments into this virtual address into calls to the initializer or setter based on the initialization state of the property at the time of assignment.
2016-03-03 15:04:38 -08:00
practicalswift
b9dd782e4b [gardening] Fix recently introduced file header. Also: "–" → "--". 2016-03-03 23:10:43 +01:00
Chris Lattner
c3c6beac72 Generalize the @noescape attribute to be a type attribute allowed
in arbitrary places.  This fixes a regression caught by SR-770 that
would otherwise be introduced by us removing automatic currying syntax,
it allows the use of @noescape on typealiases (resolving SR-824),
allows @noescape on nested function types (fixing rdar://19997680)
and allows @noescape to be used on local variables (fixing
rdar://19997577).

At this point, @noescape should stop being a decl attribute, but I'll bring
that up on swift-evolution.
2016-03-03 13:50:40 -08:00
Ben Langmuir
ceb1069199 Prefer original spelling of 'static' vs. 'class'
Try to match the original spelling of static/class in diagnostics and
when printing the AST. Also fixes cases with
PrintOptions.PrintImplicitAttrs = false, where we would just print
'class', which was not valid code.
2016-03-03 13:48:30 -08:00
Max Moiseev
cf4bafe9e3 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-03-03 13:22:03 -08:00
David Farler
e958f99acf Revert "Mangle declared interface type into NominalTypeDescriptor's Name"
This reverts commit 2262bd579a.

This information isn't necessary for field descriptor lookup,
after all. It's only the fields that need to have generic information,
which is already in the field descriptor.
2016-03-03 12:55:35 -08:00
Ben Langmuir
1182e41e01 [SourceKit] Add tags for generic parameters to annotated decl
Like typerefs, we want to show the USR in the tag.

rdar://problem/24292226
2016-03-03 12:47:09 -08:00
Chris Lattner
5ecdbfc44e Merge pull request #1528 from practicalswift/sil_invalid_minimum_witness_table_size
[gardening] Remove unused diagnostic: sil_invalid_minimum_witness_table_size
2016-03-03 12:39:39 -08:00
David Farler
2262bd579a Mangle declared interface type into NominalTypeDescriptor's Name
Previously, the mangling didn't include generics, but these are
needed to key off of the new field descriptor metadata, as well
as to construct type references for the nominal type.
2016-03-03 12:14:38 -08:00
David Farler
502c10fe12 Fix doc comment for GenericParameterDescriptor::Offset
This was a little confusing because it is actually the offset to
the first generic argument and this isn't well documented
anywhere else.
2016-03-03 11:52:31 -08:00
practicalswift
8139a0e32b [gardening] Remove unused diagnostic: sil_invalid_minimum_witness_table_size 2016-03-03 20:49:20 +01:00
Daniel Duan
e7ee507af8 Merge pull request #1520 from dduan/SR-852
[Parser][Qol] improve diagnostic with missing "self." in init
2016-03-03 08:54:40 -08:00
Slava Pestov
b3103ac7b7 Runtime: Fix alignment issue in default witness tables
The size of a protocol's metadata was not a multiple of 8 bytes, so
on 64-bit platforms, the runtime would copy default witnesses from
the wrong address, because IRGen metadata does not add alignment padding,
whereas the in-memory structure does.

Fix this by adding a 32-bit padding field at the end of the protocol
descriptor. Technically this is not necessary on 32-bit, but this keeps
things simpler for now.

The test case for this is a library evolution test exercising resilient
default protocol requirements, but it is not quite ready to go in yet.
2016-03-03 07:36:59 -08:00
Slava Pestov
874607ba48 SIL: Include all witnesses in SILDefaultWitnessTable, not just resilient defaults
Previously SILDefaultWitnessTables only included "resilient" default
implementations, which are currently defined as those that appear at the
end of a protocol, after any requirements without defaults.

However, this was too inflexible. Instead, include all entries in the
SILDefaultWitnessTable, with invalid entries standing in for requirements
without defaults.

Previously, the minimum witness table size was a separate parameter, also
appearing in SIL syntax; now it can be calculated by looking at the entries
themselves. The getResilientDefaultEntries() method of SILDefaultWitnessTable
returns the same result as getEntries() did previously.
2016-03-03 07:00:20 -08:00
Slava Pestov
0b320a6d5b Sema: Implement DefaultWitnessChecker
Now that WitnessChecker is separate from ConformanceChecker, implement
a DefaultWitnessChecker subclass which performs default witness
resolution.

This populates the recently-added ProtocolDecl::DefaultWitnesses map.

Unlike ConformanceChecker, the DefaultWitnessChecker looks up the witness
in any protocol extensions of the protocol, matching the context archetypes
of the requirement against the witness.

For now, we infer default witnesses for all protocols, but don't do
anything with that information. An upcoming SILGen patch will start to
emit thunks and add tests.
2016-03-03 06:59:55 -08:00
Daniel Duan
ea0a2d3b8d [Parser][Qol] improve diagnostic with missing "self." in init
This improvement was reported in
[SR-852](https://bugs.swift.org/browse/SR-852).

before:

```
$ cat t.swift
class A {
    init(x: Int) {}

    convenience init() { init(x: 1) }
}

$ swiftc -c t.swift
t.swift:6:13: error: initializers may only be declared within a type
    init(x: 1)
        ^
t.swift:6:17: error: expected parameter type following ':'
    init(x: 1)
            ^
t.swift:6:17: error: expected ',' separator
    init(x: 1)
            ^
           ,
t.swift:6:17: error: expected parameter type following ':'
    init(x: 1)
            ^
t.swift:6:17: error: expected ',' separator
    init(x: 1)
            ^
                                                                                                                                                       ,
```

after:

```
t.swift:6:9: error: missing 'self.' at initializer invocation
    init(x: 1)
    ^
    self.
```
2016-03-03 00:11:21 -08:00
Slava Pestov
36ef7eb0f0 Sema: Add ProtocolDecl::DefaultWitnesses
NFC for now, since the code that uses this is not checked in yet.
2016-03-02 22:12:21 -08:00
David Farler
0e6dd788cf FunctionTypeRef: Track arguments as an array, not a tuple 2016-03-02 21:25:04 -08:00
David Farler
0ab31065ff Flesh out remote memory reader
Adds a rough sketch of what will be a test harness, currently only supported
on OS X:
- Launch a child process: an executable written in Swift
- Receive the child process's Mach port
- Receive reflection section addresses and the address of a heap instance
  of interest
- Perform field type lookup on the instance remotely (TODO)
2016-03-02 21:25:04 -08:00
David Farler
cd65a8e0b0 Template metadata structures
- Add RuntimeTarget template This will allow for converting between
  metadata structures for native host and remote target architectures.

- Create InProcess and External templates for stored pointers

Add a few more types to abstract pointer access in the runtime
structures but keep native in-process pointer access the same as that
with a plain old pointer type.

There is now a notion of a "stored pointer", which is just the raw value
of the pointer, and the actual pointer type, which is used for loads.
Decoupling these allows us to fork the behavior when looking at metadata
in an external process, but keep things the same for the in-process
case.

There are two basic "runtime targets" that you can use to work with
metadata:

InProcess: Defines the pointer to be trivially a T* and stored as a
uintptr_t. A Metadata * is exactly as it was before, but defined via
AbstractMetadata<InProcess>.

External: A template that requires a target to specify its pointer size.

ExternalPointer: An opaque pointer in another address space that can't
(and shouldn't) be indirected with operator* or operator->.  The memory
reader will fetch the data explicitly.
2016-03-02 21:25:04 -08:00
David Farler
744806a742 [Reflection] Add Foreign, ObjC, and Opaque type references
These likely don't have Swift type metadata but might be useful to
record or instantiate based on what kind of metadata is encountered for
the sake of memory tools.
2016-03-02 21:25:04 -08:00
Ben Langmuir
8f9299cc97 [CodeCompletion] Add assignment to experimental operator completion
When the LHS is an lvalue/assignable tuple and there is no leading
sequence of binary expressions.

It's a bit hacky right now since we don't have a good way to
differentiate general pattern completions from builtin operators.

rdar://problem/23209683
2016-03-02 18:21:37 -08:00
Xi Ge
bafe60e91b Refactoring: move IsInSynthesizedExtension to Analyzer. NFC. 2016-03-02 17:30:11 -08:00
Xi Ge
3f20eb242d Refactoring: Moving the logic of collecting synthesized extensions to Analyzer. NFC. 2016-03-02 17:30:11 -08:00