[swift-users] libswiftCore.dylib was compiled with optimization - stepping may behave oddly;

2016-08-25 Thread David Liu via swift-users
Hi all,  can any one here give me some pointers on debugging the standard
library?
I may be compiling the toolchain incorrectly when i step through the code
variables on the stack frame are not available.
I think its due to this message when i start the REPL
`libswiftCore.dylib was compiled with optimization - stepping may behave
oddly; variables may not be available.`
I am using the /utils/build-toolchain command and did not touch the
presets.ini file.
Any help is appreciated!

Thanks in advance

Dave

Process 13833 stopped

* thread #1: tid = 0x3a6ffe, 0x0001000c3603
libswiftCore.dylib`ManagedBufferPointer.init(_uncheckedBufferClass :
AnyObject.Type, minimumCapacity : Int) -> ManagedBufferPointer
[inlined] Swift._roundUp (Swift.Int, toAlignment : Swift.Int) -> Swift.Int
at Builtin.swift:72, queue = 'com.apple.main-thread', stop reason = step in

frame #0: 0x0001000c3603
libswiftCore.dylib`ManagedBufferPointer.init(_uncheckedBufferClass :
AnyObject.Type, minimumCapacity : Int) -> ManagedBufferPointer
[inlined] Swift._roundUp (Swift.Int, toAlignment : Swift.Int) -> Swift.Int
at Builtin.swift:72 [opt]

   69  @_versioned

   70  internal func _roundUp(_ offset: Int, toAlignment alignment: Int) ->
Int {

   71_sanityCheck(offset >= 0)

-> 72return Int(_roundUpImpl(UInt(bitPattern: offset), toAlignment:
alignment))

   73  }

   74

   75  // This function takes a raw pointer and returns a typed pointer. It
implicitly

(lldb) fr v

(lldb) po offset

error: :3:1: error: use of unresolved identifier 'offset'

offset

^~

(lldb) fr v offset

error: no variable named 'offset' found in this frame

(lldb) s

Process 13833 stopped

* thread #1: tid = 0x3a6ffe, 0x0001000c3603
libswiftCore.dylib`ManagedBufferPointer.init(_uncheckedBufferClass :
AnyObject.Type, minimumCapacity : Int) -> ManagedBufferPointer
[inlined] Swift._roundUpImpl (Swift.UInt, toAlignment : Swift.Int) ->
Swift.UInt at Builtin.swift:58, queue = 'com.apple.main-thread', stop
reason = step in

frame #0: 0x0001000c3603
libswiftCore.dylib`ManagedBufferPointer.init(_uncheckedBufferClass :
AnyObject.Type, minimumCapacity : Int) -> ManagedBufferPointer
[inlined] Swift._roundUpImpl (Swift.UInt, toAlignment : Swift.Int) ->
Swift.UInt at Builtin.swift:58 [opt]

   55_sanityCheck(_isPowerOf2(alignment))

   56// Note, given that offset is >= 0, and alignment > 0, we don't

   57// need to underflow check the -1, as it can never underflow.

-> 58let x = offset + UInt(bitPattern: alignment) &- 1

   59// Note, as alignment is a power of 2, we'll use masking to
efficiently

   60// get the aligned value

   61return x & ~(UInt(bitPattern: alignment) &- 1)

(lldb) fr v

(lldb) fr v -R

(lldb) fr v aligment

error: no variable named 'aligment' found in this frame

(lldb) fr v alignment

error: no variable named 'alignment' found in this frame
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Can I do dynamic casting?

2016-08-25 Thread CK TUNG via swift-users

Since Array is a generic struct, the compiler needs know which type to use as 
the generic parameter.

What I think is do something like this below

let array:Array = [1,2,3,4,5]
let dictionary:[String:Any] = ["numbers":array]

if let value = dictionary["numbers"] {
  let type = value.dynamicType
  print(type)
  if let numbers = value as? Array {
        print(numbers + [99])
    }
  else if let numbers = value as? Array {
        print(numbers + ["99"])
  }
}

On Aug 25, 2016, at 08:39 PM, Zhao Xin via swift-users  
wrote:

Thanks, Jordan. Is there any other way to do that?

Zhaoxin

On Thu, Aug 25, 2016 at 6:40 PM, Johan Segerfeldt  
wrote:
Zhaoxin,

You are trying to cast to a type which is defined by a variable at runtime.
Casting with `as` is done at compile-time. The variable has no defined value at 
this time.

The compiler cannot infer what the value of a variable is going to be.
It can only infer types by static analysis.


Regards
Johan


Is that possible to do dynamic casting?

My code:

>
> importFoundation
>
>
>
>
>
>
>
>
> letarray = [1,2,3,4,5]
>
>
>
> letdictionary:[String:Any] = ["numbers":array]
>
>
>
>
>
>
>
>
> ifletvalue =dictionary["numbers"] {
>
>
>
> lettype = type(of: value)
>
>
>
> print(type)// Array
>
>
>
> letnumbers = valueas!Array// [1, 2, 3, 4, 5]
>
>
>
> //let numbers2 = value as! type // error: use of undeclared type 'type'
>
>
>
> }
>
>
As you can see, the dynamic casting leads an error. Is there a way to do this? 
Thanks.






Zhaoxin








___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] How to build a CLI tool which links a Swift framework? (OSX)

2016-08-25 Thread Quinn "The Eskimo!" via swift-users

On 25 Aug 2016, at 11:28, Karl via swift-users  wrote:

> I’m having a problem getting the framework and CLI tool to work together, 
> because of the Swift standard libraries …

Yep, I know this problem well.

What I do is use Xcode to create an app target, remove all the app-specific 
stuff from that, add then a `main.swift`, and add my command line code to that. 
 If I need to provide easy access to the ‘tool’ from Terminal, a quick alias or 
symlink will do the trick.

Share and Enjoy 
--
Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware


___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Implicitly type conversion ?

2016-08-25 Thread Karl via swift-users

> On 19 Aug 2016, at 18:00, Tim Vermeulen via swift-users 
>  wrote:
> 
> Any idea why Swift supports implicit casting to AnyHashable, but not to, say, 
> AnySequence?
> 

It’s a hack until existential support gets better. Explicitly casting to 
AnyHashable clutters your dictionary literals.

There’s a fair amount of code in the compiler to support it, it’s probably just 
not worth the effort for other types (and since they were never anything else, 
nothing has regressed for them as it did for AnyHashable).
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Regression in Xcode8-beta6 Swift?

2016-08-25 Thread David Hart via swift-users
I misunderstood the release notes for Xcode 8 beta 6 I read a few days ago. 
Here what will interest you:

Since ‘id’ now imports as ‘Any’ rather than ‘AnyObject’, you may see errors 
where you were previously performing dynamic lookup on ‘AnyObject’. For example 
in:

  guard let fileEnumerator = FileManager.default.enumerator(atPath: path)
  else {
return }

  for fileName in fileEnumerator {
  if fileName.hasSuffix(".txt") {
  // error: value of type ‘Element’ (aka ‘Any’) has no member
  hasSuffix
  print(fileName)
  }
}
The fix is to either cast to AnyObject explicitly before doing the dynamic 
lookup, or force cast to a

specific object type:

  guard let fileEnumerator = FileManager.default.enumerator(atPath: path)
  else {
return }

  for fileName in fileEnumerator {
  if (fileName as AnyObject).hasSuffix(".txt") {
  // cast to AnyObject
  print(fileName)
  }
}

(27639935) 



> On 25 Aug 2016, at 10:32, Quinn The Eskimo! via swift-users 
>  wrote:
> 
> 
> On 25 Aug 2016, at 09:27, David Hart  wrote:
> 
>> That proposal also says:
> 
> Indeed.  Good point.
> 
>> What was decided concerning that?
> 
> I don’t know, although given that that text was from the “Future Directions” 
> section it seems like that nothing has changed yet.
> 
> Share and Enjoy
> --
> Quinn "The Eskimo!"
> Apple Developer Relations, Developer Technical Support, Core OS/Hardware
> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Regression in Xcode8-beta6 Swift?

2016-08-25 Thread David Hart via swift-users
That proposal also says:
Deciding the fate of AnyObject lookup

We currently bestow the AnyObject existential type with the special ability to 
look up any @objc method dynamically, in order to ensure id-based ObjC APIs 
remain fluent when used in Swift. This is another special, unprincipled, 
nonportable feature that relies on the Objective-C runtime. If we change  id to 
bridge to Any, it definitely no longer makes sense to apply to AnyObject. A 
couple of possibilities to consider:

We could transfer the existing AnyObject behavior verbatim to Any.
We could attempt to eliminate the behavior as a language feature. An 
approximation of AnyObject's magic behavior can be made using operators and 
unapplied method references, in a way that also works for Swift types:

  /// Dynamically dispatch a method on Any.
  func => (myself: Any, method: (T) -> V) -> V? {
if let myself = myself as? T {
  return method(myself)
}
return nil
  }
though that's not quite the right thing for id lookup, since you want a 
respondsToSelector rather than isKindOfClass check.

We could narrow the scope of the behavior. Jordan has suggested allowing only 
property and subscript lookup off of AnyObject or Any, as a way of allowing 
easy navigation of property lists, one of the most common sources of id in 
Foundation.
If we're confident that the SDK will be sufficiently Swiftified that ids become 
relatively rare, maybe we could get away without a replacement at all.
What was decided concerning that? I felt sure that the lookup had been 
completely removed, but I’m obviously mistaken.

David.


> On 25 Aug 2016, at 09:59, Quinn The Eskimo! via swift-users 
>  wrote:
> 
> 
> On 25 Aug 2016, at 08:23, David Hart via swift-users  
> wrote:
> 
>> You can’t call arbitrary functions on AnyObject anymore.
> 
> You’re mixing up `Any` and `AnyObject`.  You can still call arbitrary methods 
> on `AnyObject`, as Martin demonstrated, but Travis’s error message referenced 
> `Any`.
> 
> SE-0116 [1] means that `Any` is a lot more common these days.
> 
> Notwithstanding the above, I don’t have any input on the change of behaviour 
> Travis is seeing.
> 
> Share and Enjoy
> --
> Quinn "The Eskimo!"
> Apple Developer Relations, Developer Technical Support, Core OS/Hardware
> 
> [1] 
> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Regression in Xcode8-beta6 Swift?

2016-08-25 Thread Quinn "The Eskimo!" via swift-users

On 25 Aug 2016, at 08:23, David Hart via swift-users  
wrote:

> You can’t call arbitrary functions on AnyObject anymore.

You’re mixing up `Any` and `AnyObject`.  You can still call arbitrary methods 
on `AnyObject`, as Martin demonstrated, but Travis’s error message referenced 
`Any`.

SE-0116 [1] means that `Any` is a lot more common these days.

Notwithstanding the above, I don’t have any input on the change of behaviour 
Travis is seeing.

Share and Enjoy
--
Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

[1] 


___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Regression in Xcode8-beta6 Swift?

2016-08-25 Thread David Hart via swift-users
You can’t call arbitrary functions on AnyObject anymore. Previously, you could 
do this:

let a: AnyObject = UIView()
a.hasPrefix(“test”) // This compiled (because hasPrefix(:_) exists on 
NSString), but would obviously crash

This is not allowed anymore.

> On 25 Aug 2016, at 03:33, Travis Griggs via swift-users 
>  wrote:
> 
> Upgrading to beta6 of Xcode8, I’ve read through various SE’s and made fixes 
> as appropriate, but the following behavior I didn’t catch an explanation as 
> to why its now an error where it was fine before.
> 
> In a ViewController, I have something that looks like:
> 
>var addButton = UIButton(type: .custom)
>var addPrompt = UILabel()
>var timesButton = UIButton(type: .system)
>var removeButton = UIButton(type: .system)
>var menuButton = UIButton(type: .system)
>   
>func commonInit() {
>[self.addButton, self.addPrompt, self.timesButton, self.removeButton, 
> self.menuButton].forEach { control in
>control.sizeToFit()
>self.addSubview(control)
>}
> 
> This code was fine until the latest update. It seemed to a heterogenous array 
> of UILabel and UIButtons was a homogeneous array of UIView objects. But now I 
> get the errors:
> 
>Value of type ‘Any’ has no member ‘sizeToFit'
>Cannot covert value of type ‘Any’ to expected argument type of ‘UIView’
> 
> This seems like it might be related to SE-0116 (Import Objective-C id as 
> Swift Any ) but I’m not sure why the inferencer can no longer find the shared 
> parent type, where it could before.
> 
> Aside, I can fix it by simply helping it a little, e.g.
> 
>[self.addButton, self.addPrompt, self.timesButton, self.removeButton, 
> self.menuButton].forEach { (control:UIView) in...
> 
> But remain curious why the inferencer can’t handle this for me anymore.
> 
> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users