carbon-lang icon indicating copy to clipboard operation
carbon-lang copied to clipboard

Proposal: static resource embedding expressions

Open hydroper opened this issue 3 years ago • 1 comments
trafficstars

Rust has include_str!("./data.txt") and include_bytes!("./data.bin") macros. So I propose the same for Carbon. In my language I use embed './data.txt':String and embed './data.bin':ByteArray.

I think C++ doesn't have that feature, but it's compatible, depending on the expression output. .NET languages support resource embedding via project configuration, not expressions.

Motivation

  • Embedding octet-stream resources through string literals (like '\0\x0a') is bad due to writting octets as code points (not all octets are legal code points) (update: no, actually U+00 to U+FF are valid). But also, it may be inefficient to parse large string literals. For example:
'\0\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff...'
  • Embedding octet-stream resources through array initializer (like [0, 0x0a]) is inefficient when the resource is large, since it'll create lots of nodes. For example:
[0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, ...]

(see the amount of numeric literals).

hydroper avatar Aug 21 '22 18:08 hydroper

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please comment or remove the inactive label. The long term label can also be added for issues which are expected to take time. This issue is labeled inactive because the last activity was over 90 days ago.

github-actions[bot] avatar Nov 20 '22 02:11 github-actions[bot]