Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP let a {.rom.} = constExpr #553

Open
timotheecour opened this issue Jan 22, 2021 · 1 comment
Open

WIP let a {.rom.} = constExpr #553

timotheecour opened this issue Jan 22, 2021 · 1 comment

Comments

@timotheecour
Copy link
Owner

timotheecour commented Jan 22, 2021

WIP proposal as alternative to the buggy let a = constExpr.unsafeAddr refs nim-lang#16794

note: const with ref types should be merged as-is (refs nim-lang#15528) and doesn't interfere with this proposal

nim-lang/RFCs#257 can be fixed in a way that doesn't break the type system as follows:

proposal 1a (mutually exclusive with 1b)

let b {.rom.} = [1,2] # b ends in ROM memory
func fn(): int = b[0] # no side effect thanks to {.rom.}
let b2 = b[0].addr
const b3 = b

IMO semantics for 1a is better than 1b, because semantically, b{.rom.} is closer to a let (gets generated in backend, has backend layout etc);

proposal 1b

const a = [1,2]
const b {.addressable.} = [1,2]
func fn(): int = b[0] # no side effect thanks to {.rom.}
let b2 = b[0].addr
const b3 = b

proposal 2 (can be done independently of 1a or 1b)

const a = [1,2]
let b {.immutable.} = [1,2]
func fn(): int = b[0] # no side effect thanks to {.rom.}
let b2 = b[0].addr

note: that variant would also allow RT values inside definition of b eg:

var x = 2
let b {.immutable.} = [1, x]

but this would preclude using b at CT in subsequent expressions

notes

can be implemented using sections, refs https://www.keil.com/support/man/docs/armclang_ref/armclang_ref_cmf1493390581125.htm

int x1 = 5;                     // Goes in .data section (default)
int y1;                         // Goes in .bss section (default)
const int z1 = 42;              // Goes in .rodata section (default)
char *s1 = "abc1";              // s1 goes in .data section (default). String "abc1" goes in .conststring section.

#pragma clang section bss="myBSS" data="myData" rodata="myRodata"
int x2 = 5;                     // Goes in myData section.
int y2;                         // Goes in myBss section.
const int z2 = 42;              // Goes in myRodata section.
char *s2 = "abc2";              // s2 goes in myData section. String "abc2" goes in .conststring section.

note

use this instead of the more hacky prepareStrMutation (nim-lang#17213) (refs nim-lang#17173)

@timotheecour timotheecour changed the title WIP let a {.rom.} = constExpr or const a {.addressable.} = constExpr WIP let a {.rom.} = constExpr Jan 22, 2021
@juancarlospaco
Copy link
Collaborator

rom

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants