News for hackers. Stuff that matters.

ash_gti

Re:The Swift compiler is slow due to how types are inferred on Wednesday June 12, 2024 @06:28PM (#40663893)
The haskell source has `let channel = "11"` vs `let channel = 11`. The example from the post is an example that looks like it should be pretty straight forward but the swift compiler falls over when you try it.

Trying it locally for example:

  # Original example
  $ time swiftc -typecheck - <<-HERE
  let address = "127.0.0.1"
  let username = "steve"
  let password = "1234"
  let channel = 11
  
  let url = "http://" + username
              + ":" + password
              + "@" + address
              + "/api/" + channel        
              + "/picture"
  
  print(url)
  
  HERE
  <stdin>:6:5: error: the compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions
   4 | let channel = 11
   5 | 
   6 | let url = "http://" + username 
     |     `- error: the compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions
   7 |             + ":" + password 
   8 |             + "@" + address 
  swiftc -typecheck - <<<''  36.38s user 1.40s system 96% cpu 39.154 total
  
  # Adding a type to one of the expression values
  $ time swiftc -typecheck - <<-HERE
  let address = "127.0.0.1"
  let username = "steve"
  let password = "1234"
  let channel = 11
  
  let url = "http://" + username
              + ":" + password
              + "@" + address
              + "/api/" + String(channel)
              + "/picture"

  print(url)
  
  HERE
  swiftc -typecheck - <<<''  0.11s user 0.03s system 74% cpu 0.192 total

Which is roughly the in line with the numbers in the original post.
Re:The Swift compiler is slow due to how types are inferred on Wednesday June 12, 2024 @06:02PM (#40663702)
The type is an inferred integer literal in swift (in the swift standard this is the `ExpressibleByIntegerLiteral`, the string literals are `ExpressibleByStringLiteral` types).

The reason this causes issues with the type checker is it has to consider all the possible combinations of the `+` operator against all the possible types that can be represented by an inferred integer literal.

This is whats causing the type checker to try every possible combination of types implementing the `+` operator, types implementing `ExpressibleByIntegerLiteral` and `ExpressibleByStringLiteral` in the standard library. That combination produces 59k+ permutations without even looking at non-standard library types.

If any of the types in the expression had an explicit type then it would be type checked basically instantly. Its the fact that none of the values in the expression have explicit types that is causing the type checker to consider so many different combinations.

Re:The Swift compiler is slow due to how types are inferred on Wednesday June 12, 2024 @04:53PM (#40662986)
Your example is different than the example in the post.

Specifically, `channel = 11`, an integer.

If it was a string then it parses very quickly.

Re:Goodbye, Node.js Buffer on Tuesday October 24, 2023 @10:28AM (#37999640)
You can use ‘atob’ and ‘btoa’ functions for some of that.
Re:Backward Compatibility, Go 1.21, and Go 2 on Monday August 14, 2023 @01:14PM (#37123654)
If you have a short lived CLI tool, disabling the GC might be useful but that’s likely an exceptional case.
Re:Checked integer arithmetic in the prospect of C23 on Monday December 19, 2022 @11:19AM (#34053843)
I know most of these are compiler intrinsically but it’s good to have them standardized.
Re:WebKit Features in Safari 16.1 on Monday October 24, 2022 @02:33PM (#33320534)
There is a setting in Preferences > Websites > Notifications to disable notifications entirely.
Re:Official IE11 end-of-life in 2 days on Monday June 13, 2022 @03:27PM (#31730460)
I dunno, then there would only be 2 actively maintained browser engines, Chrome and Firefox.

Webkit is doing pretty good on https://wpt.fyi/interop-2022 so I'm not sure why Safari should be retired.

Re:TC39 Proposal: Type Annotations on Wednesday June 08, 2022 @04:10PM (#31673312)
https://devblogs.microsoft.com/typescript/a-proposal-for-typ...

Has additional context on this proposal and has previously been linked here.

Re:Safari Technology Preview Release Notes on Friday May 13, 2022 @03:15PM (#31371501)
There is queueMicrotask (https://developer.mozilla.org/en-US/docs/Web/API/queueMicrot...) to queue onto the end of the current iteration and you can use an `await 0;` to cycle the event loop as well.
Re:Fetch API has landed into Node.js on Tuesday February 01, 2022 @03:35PM (#30168865)
Node does support ESM now by default (and has supported it for a while behind a flag), https://nodejs.org/api/esm.html
Re:Low overhead C++ interface for Apple's Metal API on Monday November 22, 2021 @09:07PM (#29313857)
> It doesn't break ARC right, it just won't do the automatic reference counting in C++ source. You can send it back and forth over the wall with CFBridgingRetain and CFBridgingRelease no?

I guess I should say that clang's ARC doesn't apply to these c++ wrappers.

The c++ code is loading symbols using the objc runtime API's to load symbols and call objc runtime APIs to dispatch the metal calls. So, you could pass these references to other objc code and it should have the correct refcounts afterwards.

Having to manually retain/release objects is a bit of a pain, but its workable.

Using a c++ RAII type to retain/release is also somewhat do-able, but I worked in a codebase that had that kind of code and it can be frustrating to get the refcounts to be correct synchronized. Although that was back with c++11, so I'm sure things have changed that would make this easier today.

Re:Low overhead C++ interface for Apple's Metal API on Monday November 22, 2021 @05:29PM (#29312321)
If the object is not autoreleased then doing a release call will deallocate the object, otherwise it will be added to the nearest autorelease pool from the current stack and be deallocated when the pool is drained.

Swift and obj-c have the same ARC semantics, so I'm not sure what you mean by swift-style refcounting. It should be identical to the obj-c ARC semantics.

https://clang.llvm.org/docs/AutomaticReferenceCounting.html outlines the ARC semantics, including the autorelease behavior.

Re:Low overhead C++ interface for Apple's Metal API on Monday November 22, 2021 @04:34PM (#29311818)
The c++ wrappings break ARC, so if you use this library you'll have to manually retain/release any object. The autorelease pool is helpful if you autorelease an object but you'll need to manually manage the memory when using this set of helpers.

In obj-c or swift, ARC would handle that for you, so this makes the memory management aspect of using Metal a bit more of a headache.

If you enable strict (https://www.typescriptlang.org/tsconfig#strict) or use the `strictBindCallApply` flag (https://www.typescriptlang.org/tsconfig#strictBindCallApply) it should check the types on call, bind and apply.
Re:Implementing a LLVM Micro C compiler in Haskell on Friday June 04, 2021 @01:32PM (#27396255)
They went with a subset of C, its enough to write a working executable. Generally for a introduction tutorial to something as complex as writing a compiler a subset like what they presented in the article is enough to show how all the pieces work together to produce a working compiler.
Re:Faster JavaScript Calls on Monday February 15, 2021 @06:22PM (#26149002)
TF can inline, but if it runs that optimization then the benchmark would be turned into a constant, so it wouldn't be measuring the call overhead of the way arguments are passed.
Re:Faster JavaScript Calls on Monday February 15, 2021 @06:17PM (#26148960)
I think this is what WASM is meant to achieve. It allows for much more precise semantics without needing to parse an AST.
Re:Swift on Windows on Tuesday September 22, 2020 @05:54PM (#24560410)
They didn't release the frameworks for those OSs.

That's like how Catalysts runtime wasn't backported to older versions of macOS.

They could decouple those frameworks from the OS, but that adds other headaches and you eventually gotta draw the line somewhere so they tend to only add new frameworks with major OS updates.

Re:Swift on Windows on Tuesday September 22, 2020 @05:10PM (#24559945)
SwiftUI isn't tied to the OS version.

It has a runtime API that should work with different versions of the OS. There were changes to the compiler that they didn't talk about until after the fact though. After SwiftUI was announced they did run those through swift-evolution.

SwiftUI for the most part is just a runtime library, the compiler changes made things a bit nicer, but most of it could be achieved without compiler changes.

> * Apple does not allow other App Stores on their platform

As a consumer, I see that as a feature not a bug. On the Switch, Play Station and Xbox I don't have other stores I can use as well. I don't see how this is a problem as much as it is a feature. The fact that Android allows more than one store is much closer to how a Windows PC allows the user to install apps from anywhere. iOS isn't trying to replicate the PC experience, its not nearly as general purpose as Windows or even macOS.

How about using a web browser with JavaScript?

Maybe not the best language for someone new but its widely available.

Re:BigInt Shipping in Firefox on Thursday May 23, 2019 @03:40PM (#19995197)
'i' suffix are often used in languages for complex numbers. For example, in ruby '1i' evaluates to 0+1i as a complex number.

I suspect they didn't want to conflate the two types.

Re:Microsoft Edge and open source collaboration on Thursday December 06, 2018 @01:29PM (#18620674)
Don't forget Opera is a re-skinned Chrome.
WebKit does support service workers now and they're working on support for Web App Manifests. Some web apps, like Kindle Web Reader work fine in offline mode on my iPhone, granted that site is using the older (deprecated) App Cache manifest.
Re:Apple Launches Portal for U.S. Users to Download Their Data on Wednesday October 17, 2018 @02:35PM (#18242169)
Apple had this in the EU since May~ish. It's now available in the US though.
Re:Apple Launches Portal for U.S. Users to Download Their Data on Wednesday October 17, 2018 @02:32PM (#18242130)
Then they would have access to my iTunes account anyway...
Re:Prepare for changes to macOS Server 5.7.1 on Monday October 01, 2018 @02:31PM (#18115457)
An alternative could be something like "Apple deprecates additional services in macOS Server 5.7.1".

That's different than the linked page but I think it gets across the changes that are coming.

Re:iOS 12 Safari Array reverse bug on Wednesday September 19, 2018 @01:47PM (#18026106)
It appears to be fixed at HEAD and in Safari Technology Preview per https://bugs.webkit.org/show_bug.cgi?id=188794

Older »