Giter VIP home page Giter VIP logo

Comments (5)

0dminnimda avatar 0dminnimda commented on May 22, 2024

The way you are supposed to do it is to have an empty array and resize it:

p = arrayof(u32).resize(4096)

And from what I can tell there's nothing terribly inefficient about it (#35 (comment))

define internal void @array() !dbg !240 {
  %.tmp1 = alloca %struct.runtime_array
  store %struct.runtime_array zeroinitializer, %struct.runtime_array* %.tmp1
  ; statement 0x3dd assignment p = arrayof(u32).resize(4096u64)
  call void @runtime_freeArray(%struct.runtime_array* %.tmp1)
  call void @runtime_resizeArray(%struct.runtime_array* %.tmp1, i64 4096, i64 4, i1 zeroext 0), !dbg !241
  call void @runtime_moveArray(%struct.runtime_array* @array_p, %struct.runtime_array* %.tmp1), !dbg !241
  ; statement 0x3e5 return
  ret void, !dbg !241
}

Which in the end quickly comes down to calling runtime_allocArray

from rune.

GavinRay97 avatar GavinRay97 commented on May 22, 2024

Ah okay, so it is more like Python/Javascript than a systems language in this regard if I understand it?
There is no notion of "fixed-size type", there is just an Array type which has a length property

from rune.

0dminnimda avatar 0dminnimda commented on May 22, 2024

The language is not complete yet, so some optimisations may be missed. It is supposed to be systems programming language.

From what I can see there's no fixed-size array, but why do you need it?
It's not more efficient than one allocation of an array of the needed size

from rune.

GavinRay97 avatar GavinRay97 commented on May 22, 2024

For two reasons:

  1. You lose the type-soundness of being able to specify "this a function that a buffer/array of a specific size"

Now instead of it being a type-level constraint, you must move this sort of information and validation into userland. This means you have a have few choices as a user:

  • A) Repeatedly validate some type like [u32] to make sure it's the right length as you pass it across your functions that expect something like [u32; 256]
  • B) Create a wrapper-class that does validation of the length in it's constructor (IE, "parses") the array. Use the wrapper class instead. But this is not suitable for high-performance code if the wrapper class isn't inlined/transparent in terms of machine code and zero-cost.
  • C) Create a "proof-type" and token, which you must pass to all methods that accept the e.g. [u32], guaranteeing that it has been validated to be the right length for the method. See: https://www.foonathan.net/2022/11/proof-types

  1. From the language/compiler perspective, there is less information in the type preserved than the user had initially provided it with. In other words, we suffer from a "lossy encoding" of information.

from rune.

0dminnimda avatar 0dminnimda commented on May 22, 2024

I thought about it and I think that if you need to specify a certain number of elements of the same type there's two cases:

  • number of elements is large, when this happens then I don't see a reason to why not write the code in the style that supports arbitrarily sizem the exact size should not matter
  • number of elements is small, then you probably assigm specific funcitons to each element of the array, so it makes more sence to name them and put them into a structure

This deals with the unnecessary checks problems

Now we can see more clearly that through "lossy encoding" compiler misses out on some optimisations for large number of elements, although the gains are probably rather not significant

I couldn't come up with an example where you really need to have a certain number of elements, maybe you have one?

from rune.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.