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

fix #10073 #10080

Closed
wants to merge 1 commit into from
Closed

fix #10073 #10080

wants to merge 1 commit into from

Conversation

@timotheecour
Copy link
Member Author

timotheecour commented Dec 23, 2018

looks like this PR helps a bit, but still fails in following case:

proc foo[N: static int](dims: array[N, int]): auto =
  const N1 = N
  let temp = N # works
  let temp2 = (a:N)
  temp2

echo foo([1, 2]) # now is ok
doAssert foo([1, 2]) == (a:2) # Error: type mismatch: got <tuple[a: static[int](2)], tuple[a: int]>

couldn't we make static convert to something else (const??) as soon as it's instantiated, to avoid special casing it everywhere via skipTypes in this PR as well as in #9046 ?

@Araq
Copy link
Member

Araq commented Dec 23, 2018

static T needs to be removed from the language IMHO. Just allow to pass integer values as type parameters turning the value N into range[0..N-1] would allow almost the same patterns without this never ending clusterfuck of bugs, edge cases and downright unspecified behaviour.

@timotheecour
Copy link
Member Author

static T needs to be removed from the language IMHO

=> we can discuss that here: https://github.com/nim-lang/Nim/issues/10085

@timotheecour timotheecour changed the title [WIP] fix #10073 fix #10073 Dec 24, 2018
@timotheecour
Copy link
Member Author

timotheecour commented Dec 24, 2018

/cc @Araq
PTAL, this unblocks #10070 and #10010

removing the WIP label to unblock this PR, the workaround for clients is simple enough (add const N1 = N for a static param N), and the other issue mentioned above in #10080 (comment) is pre-existing.

@timotheecour
Copy link
Member Author

ping @zah or @Araq

@Araq
Copy link
Member

Araq commented Dec 27, 2018

That doesn't help much.

  1. It is not clear that static T within a tuple should be allowed.
  2. It is not clear that the codegens can deal with it.

@timotheecour
Copy link
Member Author

timotheecour commented Dec 30, 2018

That doesn't help much.

that unblocks #10070 (otherwise I'd need to change the test )
EDIT: I've changed the test in ./tests/vm/tissues.nim to unblock that PR

It is not clear that static T within a tuple should be allowed.

there's a test that relies on it, see #9046 (./tests/vm/tissues.nim) added by @LemonBoy
seems also rather arbitrary to disallow static T within a tuple /cc @zah

It is not clear that the codegens can deal with it.

not sure I understand that point; I assumed by the time it reaches codegen, static[T] would already be converted to T ; CI should already cover this I believe

@Araq
Copy link
Member

Araq commented Dec 31, 2018

not sure I understand that point; I assumed by the time it reaches codegen, static[T] would already be converted to T ; CI should already cover this I believe

But static T object/tuple fields should be optimized away since they don't contain any runtime values...

@timotheecour
Copy link
Member Author

timotheecour commented Jan 6, 2019

But static T object/tuple fields should be optimized away since they don't contain any runtime values...

I still dont' understand; how is that different from behavior of const or static in example below, where it doesn't get optimized away since let a = (...) tells the compiler to convert them to a runtime value?

const Foo1 = 10
proc fun(foo4: bool, Foo5: static bool) =
  const Foo2 = 11
  let foo3 = 12
  let a = (Foo1, Foo2, foo3, foo4, Foo5) # works
  echo a

fun(true, true)

the expression in which static is used should dictate whether it should get converted to a runtime value or not

@zah
Copy link
Member

zah commented Jan 6, 2019

A more proper fix has been pushed here: #10218

@timotheecour
Copy link
Member Author

thanks a bunch @zah I verified it also passes this: #10080 (comment) ; closing this in favor of your PR

@timotheecour timotheecour deleted the exp_fix_10073 branch January 6, 2019 21:52
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

Successfully merging this pull request may close these issues.

can't build a tuple with static int element
3 participants