Re: [swift-users] Swift in bare-metal embedded programming/Swift runtime

2016-08-11 Thread Slava Pestov via swift-users
Even if you take care not to create class instances, the compiler emits many calls to runtime functions to implement features such as generics, casts and existentials. It is possible to write code where a large number of runtime calls are optimized away, but I don’t think they can be eliminated

Re: [swift-users] Swift in bare-metal embedded programming/Swift runtime

2016-08-16 Thread Slava Pestov via swift-users
> On Aug 15, 2016, at 3:36 PM, Rick Mann wrote: > > Well, even C++ requires some amount of run time. On a larger MCU, the runtime > shouldn't be a problem at all. What I want to do is minimize the amount of OS > I have to implement. For example, using newlib > (https://sourceware.org/newlib/

Re: [swift-users] Capturing difference with typealias

2016-08-19 Thread Slava Pestov via swift-users
Hi Jon, In beta 6, non-escaping is now the default, and you must use the @escaping attribute to declare a parameter as escaping. Unfortunately, there were a few bugs in how this attribute was implemented. I checked in a fix to the swift-3.0-branch today: https://github.com/apple/swift/commit/c

Re: [swift-users] Element vs. Iterator.Element

2016-11-02 Thread Slava Pestov via swift-users
I don’t remember the details, but IIRC ‘Iterator’ is an inferred associated type on Array, so it cannot appear in the ‘where’ clause of an extension. This is a known limitation of the name lookup code — presently it cannot recur into associated type inference due to circularity. We plan on addre

Re: [swift-users] Weird protocol behaviour.

2016-12-25 Thread Slava Pestov via swift-users
> On Dec 22, 2016, at 4:43 PM, Howard Lovatt via swift-users > wrote: > > The following variation works: > > protocol P {} > > class P1:P {} > > class X:P1 {} > > func foo(_ x:A) {} > > func bar() { > //let x = X() // this compiles > let x = X() as P1 // this does not compile. Why?

Re: [swift-users] Compiler crashes while resolving generics constraints

2016-12-25 Thread Slava Pestov via swift-users
Hi Igor, Your example is not self-contained, so I added the following definitions: struct URI {} struct App { class Remote { struct Credentials {} } } struct RemoteUser {} protocol ResponseRepresentable {} protocol RemoteCredentials {} Unfortunately, this makes the code compile in b

Re: [swift-users] Compiler crashes while resolving generics constraints

2016-12-26 Thread Slava Pestov via swift-users
t’s talking about the two different types (both named ‘Remote’). If you feel this behavior is in error, do you mind filing a JIRA bug? Slava > > >> 25 дек. 2016 г., в 23:50, Slava Pestov via swift-users >> mailto:swift-users@swift.org>> написал(а): >> >>

Re: [swift-users] Compiler crashes while resolving generics constraints

2016-12-26 Thread Slava Pestov via swift-users
орь Никитин wrote: > > Now I’m not sure that it’s a compiler bug. > Maybe I not provide enough info of the type system or whatever else > > Thanks for the help! > >> 26 дек. 2016 г., в 22:49, Slava Pestov via swift-users >> mailto:swift-users@swift.org>> написал

Re: [swift-users] Weird protocol behaviour.

2016-12-30 Thread Slava Pestov via swift-users
When you call foo(_: A) with a concrete type C, the type checker performs a conformance check of C to P. If C is a protocol type, the conformance check fails. Ie, unlike the subtype relation (roughly, “I can assign a value of this type to that”), the conformance relation (“I can substitute this

Re: [swift-users] inout generic struct parameter error

2017-01-01 Thread Slava Pestov via swift-users
Nice catch. Here’s a minimal test case: struct G {} func f1(_: inout G) {} func f2(_: inout G) {} func g1(t: G) { let _ = f1(&t) // cannot pass immutable value as inout argument: 't' is a 'let' constant } func g2(t: G) { let _ = f2(&t) // cannot convert value of type 'G' to expected argume

Re: [swift-users] Is it possible to compile swift code to dynamic library?

2017-01-09 Thread Slava Pestov via swift-users
Right now, we don’t have an ‘official’ way to expose Swift APIs to C. However there is the completely unsupported and subject to change or removal at any time @_cdecl attribute. Eg, @_cdecl(“bar_foo") public func foo(x: Int) -> Int { return x } This defines a function callable from C as: exter

Re: [swift-users] make a static/class method return type be the subclass it is called with

2017-01-10 Thread Slava Pestov via swift-users
> On Jan 9, 2017, at 11:59 PM, Pierre Monod-Broca via swift-users > wrote: > > Hi again, > > You might want to look at Self requirement in protocols for exemple: > protocol P { > func items(/*...*/) -> [Self] > } > class C: P { > func items(/*...*/) -> [C] { >... > } > } FWIW, this req

Re: [swift-users] [swift-evolution] Best way to handle escaping function that might throw

2017-01-12 Thread Slava Pestov via swift-users
> On Jan 11, 2017, at 2:02 PM, Howard Lovatt via swift-evolution > wrote: > > Another possibility, other than generics, would be to drop rethrows all > together and have the compiler infer if a throw is possible or not, including: > > struct FStore { > let f: () throws -> Void >

Re: [swift-users] Exclamation mark's in swift parameter listings?

2017-01-18 Thread Slava Pestov via swift-users
For what it’s worth, if T is a reference type or Unsafe*Pointer, then T and Optional have the same exact representation in memory. The compiler is smart enough to know that a non-optional pointer can never be NULL, so a NULL value of the underlying type can be used to unambiguously encode the ‘

Re: [swift-users] Exclamation mark's in swift parameter listings?

2017-01-18 Thread Slava Pestov via swift-users
Boxing usually refers to out-of-line allocation of values on the heap. For example, values of protocol type (as well as Any) will box their payload, depending on size. Slava > On Jan 18, 2017, at 10:53 PM, Rien wrote: > > Thanks Slava, > > Then my memory wasn’t that bad. This is indeed what

Re: [swift-users] Protocol extension gotcha... or bug?

2017-01-23 Thread Slava Pestov via swift-users
> On Jan 23, 2017, at 7:31 AM, Wagner Truppel via swift-users > wrote: > > Say you have a protocol and an extension of it, like so: > > protocol P { > var item: String { get } > } > > extension P { > var item: String { > return "P" > } > } > > Now imagine a class that conforms to

Re: [swift-users] Initializers

2017-01-27 Thread Slava Pestov via swift-users
> On Jan 27, 2017, at 10:39 AM, tuuranton--- via swift-users > wrote: > > Yes, but why? > > What's the rationale for this? > > What would be so bad about allowing overriding a non-failable initializer > with a failable initializer? If the non-failable initializer witnesses a non-failable pr

Re: [swift-users] Static type when expecting dynamic type

2017-02-02 Thread Slava Pestov via swift-users
The problem is were not marking the materializeForSet accessor in DefaultMutableReference.value as an override. Definitely a bug: sil_vtable DefaultMutableReference { #MutableReference.init!initializer.1: _TFC1d23DefaultMutableReferencecfT_GS0_x_ // DefaultMutableReference.init() -> Def

Re: [swift-users] Collection Oddities

2017-02-07 Thread Slava Pestov via swift-users
> On Feb 7, 2017, at 8:14 PM, Guillaume Lessard via swift-users > wrote: > > I keep running into weird things with Swift 3 Collections. > > A) Collection has its count property defined as an Int via IndexDistance: > > public protocol Collection : Indexable, Sequence { >associatedtype Inde

Re: [swift-users] How flatMap's signature is able to translate from Optional to [Type]?

2017-02-13 Thread Slava Pestov via swift-users
> On Feb 13, 2017, at 4:40 PM, Maxim Veksler via swift-users > wrote: > > I'm trying to understand the signature of flapMap that allows it to "strip > down" Optional from a type, when called on an Optional collection but remain > same type when called on a non option collection. > > How woul

Re: [swift-users] Getting started with development

2017-02-13 Thread Slava Pestov via swift-users
Here is the general guide for contributions: https://swift.org/contributing/ If you want ideas for simple things to fix, look at the ‘StarterBug’ label in the bug tracker: https://bugs.swift.org/issues/?jql=status%20in%20(Open%2C%20Reopened)%20AND%20labels%20%3

Re: [swift-users] fileprivate extensions can't add protocol conformance

2017-02-14 Thread Slava Pestov via swift-users
> On Feb 13, 2017, at 11:57 PM, Alejandro Martinez via swift-users > wrote: > > "is currently required to have the same visibility as the protocol itself" > > that makes sense. I guess my question is more, is there a technical > reason for it? The runtime and compiler do not support ‘non publ

Re: [swift-users] The case of broken polymorphism or "Cannot convert value of type to expected argument type"?

2017-02-16 Thread Slava Pestov via swift-users
Hi Isaac, This is not about associated types. Rather, the issue is that a ‘Thing’ is a ‘Something’, but you are casting it to ‘Something’. The two types are not related; in general, if A is a subtype of B, then G is not a subtype of G. https://en.wikipedia.org/wiki/Covariance_and_contravarianc

Re: [swift-users] The case of broken polymorphism or "Cannot convert value of type to expected argument type"?

2017-02-21 Thread Slava Pestov via swift-users
> On Feb 20, 2017, at 4:07 PM, Howard Lovatt wrote: > > It is confusing in Swift what can be covariant and what is invariant, > consider: > > // Covarant arrays work > class A {} > class B: A {} > let a = A() // A > let b = B() // B > var arrayA = [a] // Array > arr

Re: [swift-users] The case of broken polymorphism or "Cannot convert value of type to expected argument type"?

2017-02-21 Thread Slava Pestov via swift-users
> On Feb 20, 2017, at 4:17 PM, Jon Shier wrote: > > Also possibly related is the covariance in protocol requirements. The > following example doesn’t compile without casting the arrays or single values > to the exact types required in the protocols, despite being covariant through > protocol

Re: [swift-users] Weird function call behaviour

2017-02-22 Thread Slava Pestov via swift-users
When a class conforms to a protocol and a requirement is fulfilled by a method in an extension, the class does not get a vtable entry for the extension method. So it cannot be overridden in a subclass — there’s nothing to dynamically dispatch here. We plan on addressing this as part of ABI stabi

Re: [swift-users] Weird function call behaviour

2017-02-22 Thread Slava Pestov via swift-users
> On Feb 22, 2017, at 1:01 PM, David Hart wrote: > > >> On 22 Feb 2017, at 21:59, Slava Pestov via swift-users >> mailto:swift-users@swift.org>> wrote: >> >> When a class conforms to a protocol and a requirement is fulfilled by a >> method in

Re: [swift-users] question about covariant subtyping

2017-02-22 Thread Slava Pestov via swift-users
It looks intentional. Function conversions can be performed on argument and return types that are related via ‘Subtype’ constraints in the constraint solver, however array conversions are only possible via the ‘Conversion’ relation. Changing this would require some additional work in SILGen to

Re: [swift-users] question on generics

2017-02-22 Thread Slava Pestov via swift-users
> On Feb 22, 2017, at 4:23 PM, David Sweeris via swift-users > wrote: > > >> On Feb 22, 2017, at 16:08, Dave Reed via swift-users >> wrote: >> >> I suspect this can't be done (at least not right now), but wanted to check. >> >> I'd like to declare a class as a generic that meets a protocol

Re: [swift-users] inline best practices?

2017-03-02 Thread Slava Pestov via swift-users
Here’s an overview of @inline(__always): - It is an annotation for the performance inliner, which only runs in -O builds. The performance inliner uses heuristics to figure out what to inline, so most of the time explicit annotations are not necessary, and sometimes it won’t inline something eve

Re: [swift-users] Protocol conformance failure

2017-03-21 Thread Slava Pestov via swift-users
Worth mentioning that @objc protocols do conform to themselves as long as they do not have static methods or initializer requirements. However this may be too heavy-handed if a simple overload can do the trick. Slava > On Mar 9, 2017, at 1:10 PM, Guillaume Lessard via swift-users > wrote: >

Re: [swift-users] withoutActuallyEscaping example question

2017-03-26 Thread Slava Pestov via swift-users
Hi Ray, There are two overloads of filter() available on ‘array.lazy’; the version that takes an escaping closure and returns a LazyFilterCollection, and the version that takes a non-escaping closure and returns [Int]. In the first example, we pick the LazyFilterCollection-returning overload,

Re: [swift-users] withoutActuallyEscaping example question

2017-03-26 Thread Slava Pestov via swift-users
) -> Bool) -> [Int] { return array.lazy.filter { predicate($0) } } Slava > On Mar 26, 2017, at 1:14 AM, Slava Pestov via swift-users > wrote: > > Hi Ray, > > There are two overloads of filter() available on ‘array.lazy’; the version > that takes an esc

Re: [swift-users] Compile time tests

2017-03-31 Thread Slava Pestov via swift-users
We have an undocumented -verify flag you can use for this. Here’s some code that doesn’t type check because the second call to g() is passing a type that does not conform to protocol P: protocol P {} protocol Q {} struct R : P {} struct S : Q {} func g(_: T) {} g(R()) g(S()) // expected-error

Re: [swift-users] Swift creduce

2017-04-19 Thread Slava Pestov via swift-users
Huon noticed that creduce actually works pretty well with Swift as-is. I’ve been using it without any issues. Slava > On Apr 19, 2017, at 3:53 PM, Doug Hill via swift-users > wrote: > > Is there a version of 'creduce' for Swift? > > I did some basic googling and didn't find anything, so I th

Re: [swift-users] Performance in Trunk builds vs 3.1.1

2017-04-25 Thread Slava Pestov via swift-users
Can you share the code for your benchmark? Slava > On Apr 25, 2017, at 6:34 AM, Proyb P via swift-users > wrote: > > I have testing the performance between trunk builds downloaded from Swift > website (April 22 and 24) and 3.1.1 > > Fibonacci (N: 50) benchmark: > Trunk (22 Apr): 1m13s > Trun

Re: [swift-users] How to use a protocol to infer a generic type with constraints

2017-05-02 Thread Slava Pestov via swift-users
Hi Satoshi, Protocols do not conform to themselves. Only concrete types can conform to protocols in the current implementation of Swift. Slava > On May 2, 2017, at 1:57 AM, Satoshi Nakagawa via swift-users > wrote: > > Hi, > > I got a build error "Generic parameter 'T' could not be inferred

Re: [swift-users] Swift build-script Smaller Memory Footprint?

2017-05-07 Thread Slava Pestov via swift-users
On Darwin (which uses its own linker and not GNU ld), you can definitely build Swift with less than 16GB of RAM available. Maybe you could try gold? Slava > On May 6, 2017, at 7:21 PM, Brandon B via swift-users > wrote: > > Hello, > > I’m installing Swift 3 on FreeBSD 11. After installing t

Re: [swift-users] override-like keyword for default implementations

2017-05-16 Thread Slava Pestov via swift-users
It’s not clear if such a keyword can be designed in a way that covers all cases. For example, consider a protocol extension that provides a default implementation for a requirement in a different protocol: protocol R { func f() } protocol P {} extension P { func f() } struct S : R, P {}

Re: [swift-users] swift 4.0 "swift-version 4" errors with "type(of:"

2017-05-19 Thread Slava Pestov via swift-users
Do you have a member named ‘type’ in the current scope? We changed the behavior of type(of:) so that it behaves like a normal declaration in the Swift module instead of a special keyword. Unfortunately this means if you have a ‘type’ already visible in scope, you have to fully qualify Swift.typ

Re: [swift-users] Swift 4.0 forEach problem

2017-05-19 Thread Slava Pestov via swift-users
Thanks, do you mind filing a bug at bugs.swift.org ? Slava > On May 19, 2017, at 4:18 PM, Edward Connell via swift-users > wrote: > > In swift 3.1.1 I was able to have the function below, which "gets" an > optional member collection of objects and calls their setModel

Re: [swift-users] Associatedtype Naming Conventions

2017-05-31 Thread Slava Pestov via swift-users
Can you give an example of a problematic name collision? Does fully qualifying names not help? Slava > On May 31, 2017, at 4:01 PM, Steven Brunwasser via swift-users > wrote: > > Hi, > > I have a library which uses a few generic protocols with identically named > associated types that may n

Re: [swift-users] Associatedtype Naming Conventions

2017-05-31 Thread Slava Pestov via swift-users
> On May 31, 2017, at 4:16 PM, Steven Brunwasser wrote: > > Basically, my library contains a bunch of collection-like protocols, which > can be combined in different ways and can be compatible with each other in > certain combinations when the proper types align. Naturally, they all have an >

Re: [swift-users] Swift 4 protocol with associatedtype conforming to itself

2017-06-07 Thread Slava Pestov via swift-users
This is a rather complex feature that is not actually implemented in Swift 4 (or Swift 3 for that matter). Work is underway to support this, though. The fact that the second example does not produce a diagnostic is a bug (probably you will not be able to define a type that conforms to P2 anyway)

Re: [swift-users] Swift 4 protocol with associatedtype conforming to itself

2017-06-07 Thread Slava Pestov via swift-users
> On Jun 7, 2017, at 12:46 AM, Jens Persson wrote: > > Ok, I thought it was part of SE-0142 (which has status "implemented (Swift > 4)”. That’s just the where clause part. There’s still plenty you can accomplish with them even if they do not introduce recursive conformances :) Slava > /Jens

Re: [swift-users] Optional generics question

2017-06-08 Thread Slava Pestov via swift-users
> On Jun 8, 2017, at 11:11 AM, Joel Loeshelle via swift-users > wrote: > > Hi all, > > Is there any support for having an optional type in an initializer? My use > case is I want to have a struct SectionWrapper that includes information > about a Collection View Section. So you can pass the

Re: [swift-users] Extensions on Typealiased Existential Protocols

2017-06-19 Thread Slava Pestov via swift-users
Hi Steven, > On Jun 19, 2017, at 11:44 AM, Steven Brunwasser via swift-users > wrote: > > Is this error intentional, or a bug? It’s intentional. We could add support for this as an extra bit of sugar, but note that > Since extension A where Self: B is the same as extension B where Self: A,

Re: [swift-users] Is "lazy let" on the schedule anywhere?

2017-06-26 Thread Slava Pestov via swift-users
If you’re not passing the value type as an inout, how will the ‘lazy let’ property write back the new value? Slava > On Jun 26, 2017, at 3:32 PM, Edward Connell via swift-users > wrote: > > It sure would be nice if the compiler supported lazy lets for structs. Any > idea when or if this will

Re: [swift-users] How to add this generic static func as a protocol requirement?

2017-07-07 Thread Slava Pestov via swift-users
Try using an associated type for the result of foo(): protocol P { associatedtype R static func foo(_ v: T) -> R } Slava > On Jul 7, 2017, at 1:50 AM, Jens Persson via swift-users > wrote: > > protocol P { > // … > // For example the following will not work: > // static func

Re: [swift-users] Is there any harm that an @escaping handler never called?

2017-07-11 Thread Slava Pestov via swift-users
No, there is no requirement to invoke a closure at least once, escaping or not. Slava > On Jul 11, 2017, at 3:55 PM, Zhao Xin via swift-users > wrote: > > For example, I have an async query, I pass it an `@escaping resultHandler`. > If there is any results, the handler will run. However, if t

Re: [swift-users] Printing Enums?

2017-07-17 Thread Slava Pestov via swift-users
There’s already a radar filed for this (I don’t know if there’s a JIRA bug though). The problem is that the standard library’s reflection mechanism only knows how to map the in-memory representation of an enum to a case name for native Swift enums. Objective-C enums are represented by their ‘ra

Re: [swift-users] Convenience initializers in structs?

2017-07-18 Thread Slava Pestov via swift-users
Hi Jens, While I’m not familiar with the integer API in the standard library, structs and enums certainly can have convenience initializers. They must delegate to another initializer (either convenience or designated) rather than initializing the fields of the type one by one. Slava > On Jul

Re: [swift-users] Convenience initializers in structs?

2017-07-18 Thread Slava Pestov via swift-users
> On Jul 18, 2017, at 3:54 PM, Chris McIntyre > wrote: > > Was it ever explained why the syntax is different? > Oh. I think convenience initializers on classes are marked as such explicitly because convenience vs designated has an effect on the ABI of an initializer, for the purposes of inh

Re: [swift-users] ⁨Is it possible to store a set of heterogeneous items with protocol?

2017-07-18 Thread Slava Pestov via swift-users
Hopefully we will one day have generalized existentials which would at least allow a heterogeneous array of protocols with an associated type; however it is not clear how such an existential could conform to Hashable in a general way, given that Hashable implies Equatable which has a Self requir

Re: [swift-users] Constraining the conforming type of a protocol

2017-07-29 Thread Slava Pestov via swift-users
What you’re trying to do should be equivalent to this: protocol Toggling : Equatable { … } It’s a bug that placing the constraint on ‘Self’ does not have the same effect though; do you mind filing a JIRA? Slava > On Jul 29, 2017, at 12:24 PM, Ray Fix via swift-users > wrote: > > Hi, > >

Re: [swift-users] @_transparent allowing a data member inside an enum inside MemoryLayout.swift

2017-08-02 Thread Slava Pestov via swift-users
> On Aug 2, 2017, at 4:01 PM, Shyamal Chandra via swift-users > wrote: > > Hi, > > After reading the Ray Wenderlich website tutorial [1] about Unsafe Swift, I > was checking out this file [3] inside swift/stdlib/public/core titled > MemoryLayout.swift. However, I was confused about the @_tr

Re: [swift-users] Question with calling a method which returns `Self` on super

2017-08-10 Thread Slava Pestov via swift-users
Hi Lincoln, This is a known issue with ‘super’ method calls: https://bugs.swift.org/browse/SR-1736 A workaround is to cast the result of the supermethod call to Self explicitly: let copied = super.copy() as! Self Slava > On Aug 10, 2017, at 8:16 PM, 吴君恺

Re: [swift-users] Question with calling a method which returns `Self` on super

2017-08-10 Thread Slava Pestov via swift-users
> On Aug 10, 2017, at 8:23 PM, Slava Pestov via swift-users > wrote: > > Hi Lincoln, > > This is a known issue with ‘super’ method calls: > https://bugs.swift.org/browse/SR-1736 <https://bugs.swift.org/browse/SR-1736> > > A workaround is to cast the resul

Re: [swift-users] Where to download Swift v.3.2 for Linux?

2017-08-24 Thread Slava Pestov via swift-users
HI Mr Bee, “Swift 3.2” refers to running the Swift 4.0 compiler with the -swift-version 3 flag. It is not a separate download. Slava > On Aug 24, 2017, at 7:44 AM, Mr Bee via swift-users > wrote: > > Hi all, > > I'm now using Swift v.3.0 on Linux (ubuntu) and about preparing to migrate to

Re: [swift-users] Swift4/iOS question

2017-08-28 Thread Slava Pestov via swift-users
> On Aug 28, 2017, at 1:58 PM, Travis Griggs via swift-users > wrote: > > If I need to take this question elsewhere, please point me to the right list. > > I decided to take the dive this morning and give XCode9 beta and Swift 4 a > try. I’m tired of not being able to refactor. > > There are

Re: [swift-users] Type of expression is ambiguous for static tuples

2017-09-01 Thread Slava Pestov via swift-users
Yeah, my understanding is that .foo syntax only works if ‘foo’ is an immediate static member of the contextual type where the expression appears. So nested member access like .foo.b ar does not make sense. Slava > On Sep 1, 2017, at 6:04 AM, Adrian Zubarev via swift-users > wr

Re: [swift-users] Type alias with a "where" clause specifying required associated type

2017-09-04 Thread Slava Pestov via swift-users
Hi Rudolf, What you are describing is not possible right now. The protocol PointType cannot be used as a type at all, because it has an associated type requirement. Also it is not clear what a ‘where’ clause attached to a type alias would mean. There has been some discussion of ‘generalized exi

Re: [swift-users] Is this a compiler bug?

2017-09-04 Thread Slava Pestov via swift-users
Yeah, looks like a bug. Do you mind filing a JIRA? Slava > On Sep 4, 2017, at 8:55 PM, Howard Lovatt via swift-users > wrote: > > Hi All, > > Is this a compiler bug? > > struct Box { > var value: T > init(_ value: T) { self.value = value } > /// Unboxing operator. > static fu

Re: [swift-users] Type alias with a "where" clause specifying required associated type

2017-09-05 Thread Slava Pestov via swift-users
It’s just placeholder syntax for ‘a value whose type is given by a generic parameter in the following signature’. Slava > On Sep 5, 2017, at 4:44 AM, Rudolf Adamkovič wrote: > > I see. TBH, I don’t understand why it says “Any” in the "generalized > existentials” but everything else is clear.

Re: [swift-users] Can you use @autoclosure in a setter?

2017-09-11 Thread Slava Pestov via swift-users
You can have valueSource store a closure that captures the autoclosure value. For example, set { valueSource = { newValue } } Slava > On Sep 11, 2017, at 11:04 AM, Nevin Brackett-Rozinsky via swift-users > wrote: > > Hi, quick question here: > > I have a class with a property that needs t

Re: [swift-users] Can you use @autoclosure in a setter?

2017-09-11 Thread Slava Pestov via swift-users
ted > to produce `newValue`. So this will not accomplish what Nevin is trying to > do. > >> On Sep 11, 2017, at 3:08 PM, Slava Pestov via swift-users >> mailto:swift-users@swift.org>> wrote: >> >> You can have valueSource store a closure that captures th

Re: [swift-users] Can you use @autoclosure in a setter?

2017-09-11 Thread Slava Pestov via swift-users
gt; Slava > >> On Sep 11, 2017, at 3:11 PM, Hooman Mehr > <mailto:hoo...@mac.com>> wrote: >> >> But the expression that is assigned to the property will be eagerly >> evaluated to produce `newValue`. So this will not accomplish what Nevin is >> tryin

Re: [swift-users] Can't implement generic subscript in protocol

2017-09-15 Thread Slava Pestov via swift-users
> On Sep 15, 2017, at 12:40 PM, Joanna Carter via swift-users > wrote: > > Greetings > > Now we've got generic subscripts, I thought I'd play… > > protocol DataProvider > { > subscript(index: Int) -> itemType { get } > } This is a valid usage of your protocol: func doesStuff(p: DataProvide

Re: [swift-users] Can't implement generic subscript in protocol

2017-09-15 Thread Slava Pestov via swift-users
> On Sep 15, 2017, at 12:40 PM, Joanna Carter via swift-users > wrote: > > Xcode Version 9.0 (9A235) > > Hmmm. I'm now getting a segmentation fault : 11 on a constructor when trying > to implement type erasure : Swift 4.0 had issues with members and member references named ‘subscript’. On m

Re: [swift-users] Can't implement generic subscript in protocol

2017-09-15 Thread Slava Pestov via swift-users
> On Sep 15, 2017, at 4:26 PM, Slava Pestov wrote: > > >> On Sep 15, 2017, at 12:40 PM, Joanna Carter via swift-users >> wrote: >> >> Xcode Version 9.0 (9A235) >> >> Hmmm. I'm now getting a segmentation fault : 11 on a constructor when trying >> to implement type erasure : > > Swift 4.0 h

Re: [swift-users] How to resolve "type(of: instance)" being shadowed by "instance.type"?

2017-09-22 Thread Slava Pestov via swift-users
> On Sep 22, 2017, at 10:10 PM, Glen Huang via swift-users > wrote: > > I have a class like this: > > class File { > type: FileType > url: URL > func fetch(from server: Server) { > type(of: server).get(from: url) > } > } > > However, it fails to compile with "Cannot call value o

Re: [swift-users] How to check the type of a concrete class that inherits from a generic class?

2017-10-06 Thread Slava Pestov via swift-users
Can you post a self-contained example, including the declaration of NSFetchedResultsController? Slava > On Oct 6, 2017, at 11:28 PM, Glen Huang via swift-users > wrote: > > Hi, > > I defined some concrete classes inheriting from a generic class like this: > > class Controller1: NSFetchedRes

Re: [swift-users] How to check the type of a concrete class that inherits from a generic class?

2017-10-06 Thread Slava Pestov via swift-users
Oh I see. I think the problem is that with Objective-C generics, you can always cast from Foo to Foo, because the type parameters do not really exist. Swift’s type checking logic for casts assumes Swift generic semantics, where in general Foo and Foo are unrelated types. Do you mind filing a bu

Re: [swift-users] How to check the type of a concrete class that inherits from a generic class?

2017-10-06 Thread Slava Pestov via swift-users
You can try upcasting the value to NSObject first, and then performing a conditional downcast to Controller1 and Controller2. At this point the type checker will not have enough information to decide that the cast always fails, and should no longer emit a warning. Slava > On Oct 6, 2017, at 11

Re: [swift-users] [Feature Request] Extend the `defer` statement

2017-10-08 Thread Slava Pestov via swift-users
I think you can achieve what you want by having the ‘defer’ block capture a mutable local variable. Eg, func doStuff() { var success = false defer { if !success { // do some additional cleanup } } … success = true … return result } > On Oct 8, 2017, at 7:34 PM, Jun

Re: [swift-users] Question about typo fixes on the Swift website.

2017-10-09 Thread Slava Pestov via swift-users
Alternatively, a pull request to fix those typos would be most welcome! Slava > On Oct 9, 2017, at 12:58 AM, Alex Blewitt via swift-users > wrote: > > Probably the best place would be to file an issue at https://bugs.swift.org > and it can be routed from there. > >

Re: [swift-users] Expression was too complex to be solved in reasonable time

2017-10-24 Thread Slava Pestov via swift-users
> On Oct 24, 2017, at 3:05 PM, Nate Birkholz via swift-users > wrote: > > Doing a tutorial from RayWenderlich. > https://www.raywenderlich.com/125313/make-game-like-candy-crush-spritekit-swift-part-4 > >

Re: [swift-users] Redundant superclass constraint

2017-10-25 Thread Slava Pestov via swift-users
Hi Phil, I think the warning is bogus in this case. Do you mind filing a bug? Slava > On Oct 24, 2017, at 11:00 PM, Phil Kirby via swift-users > wrote: > > Original StackOverflow post: > > https://stackoverflow.com/questions/46924554/redundant-superclass-constraint-in-swift-4 > >

Re: [swift-users] How to store ref to any kind of function, and call with it argument list?

2017-11-03 Thread Slava Pestov via swift-users
Unfortunately we don’t have a way to invoke a function with a runtime argument list because that would require runtime code generation in the most general case. I would hack around it by handling the common cases of no arguments, 1 argument, 2 arguments, etc up to some fixed number of arguments

Re: [swift-users] How to store ref to any kind of function, and call with it argument list?

2017-11-03 Thread Slava Pestov via swift-users
(Int) -> Int is not a subtype of (Any) -> Any, because a value of the latter type can be called with an argument type that is not an Int, for example a String: let fn: (Int) -> Int = … let fn2 = (Any) -> Any = fn // pretend this works fn2(“hi”) // what does this do? I think you’ll need to do s

Re: [swift-users] Functions getting compiled multiple times

2017-11-05 Thread Slava Pestov via swift-users
> On Nov 5, 2017, at 12:23 PM, Dan Stenmark via swift-users > wrote: > > I’ve recently been profiling our compile times using the > -debug-time-function-bodies flag, and I’ve noticed that some functions seem > to be listed multiple times. I know that -debug-time-function-bodies isn’t > som

Re: [swift-users] Where to read about *.swiftmodule file format?

2017-11-28 Thread Slava Pestov via swift-users
Hi Volodymyr, The format is not documented anywhere and is subject to change. A good starting point is include/swift/Serialization/ModuleFormat.h, but I would first be curious to know what exactly you’re planning on doing with it. It might be better to extend swift-ide-test and similar utilitie

Re: [swift-users] Experimenting with conditional conformances

2017-11-28 Thread Slava Pestov via swift-users
Hi Antonio, This is explicitly mentioned in the original proposal. We do not allow multiple conditional conformances to be defined for the same type. Instead, is it possible to express your conformance as follows? extension Array : Intertial where Element : Inertial { … } Or do you really need

Re: [swift-users] Multiple Class Types in Protocol Composition

2017-12-07 Thread Slava Pestov via swift-users
Hi Mario, You’re right that this part of the proposal was not fully implemented. Computing the common ancestor of two superclasses is a little tricky here because it would force us to resolve the superclass type of a class when realizing a subclass existential. This would introduce circular dep

Re: [swift-users] Swift's method dispatch

2017-12-08 Thread Slava Pestov via swift-users
Hi Jens, I think the problem is that overload ranking always prefers a protocol requirement to a protocol extension member, because usually you want the dynamic dispatch through the requirement instead of calling the default implementation. But it appears that this heuristic does not take into

Re: [swift-users] Compiler fLag to activate SE-0143 (conditional conformance)?

2017-12-14 Thread Slava Pestov via swift-users
> On Dec 14, 2017, at 10:56 AM, torquato via swift-users > wrote: > > > SE-0143 has been accepted, but is not activated by default in the last > builds. As per Snapshot 2017-12-06 I get the Error message: "Conditional > conformance of 'Array' to 'Foo' depends on an experimental feature > (

Re: [swift-users] Compiler fLag to activate SE-0143 (conditional conformance)?

2017-12-17 Thread Slava Pestov via swift-users
> On Dec 14, 2017, at 7:42 PM, Dave Abrahams wrote: > > IMO it makes as much sense to mention the flag in the proposal as it does to > point at a proof-of-concept implementation that accompanies a proposal. > Generally we only accept proposals that “have an implementation” these days. I be

Re: [swift-users] Superclass constraint cannot depend on type parameter

2016-03-19 Thread Slava Pestov via swift-users
Hi Jon, You are right that this is a limitation of the current implementation in Swift 2.2. I may have fixed this recently in master: https://github.com/apple/swift/commit/3aacf5d805768527b59d24e6da2a03911b3dd5b0