[v2] Nested object declaration -> "Expression too complex"?

Discuss the future of the AutoHotkey language
swagfag
Posts: 4034
Joined: 11 Jan 2017, 17:59

[v2] Nested object declaration -> "Expression too complex"?

29 Jul 2018, 20:59

i tried to create the following object, then this error msg popped up, which appears to be a rewrite from v1's "Expression too long":

Code: Select all

; expression too complex
Matrix := {
	"0": {
		-3: [0, 0, 0, 0],
		-2: [0, 0, 0, 0],
		-1: [0, 0, 0, 0],
		 0: [0, 0, 0, 0],
		 1: [0, 0, 0, 0],
		 2: [0, 0, 0, 0],
		 3: [0, 0, 0, 0],
	},
	"1": {
		-3: [0, 0, 0, 0],
		-2: [0, 0, 0, 0],
		-1: [0, 0, 0, 0],
		 0: [0, 0, 0, 0],
		 1: [0, 0, 0, 0],
		 2: [0, 0, 0, 0],
		 3: [0, 0, 0, 0],
	},
	"2": {
		-3: [0, 0, 0, 0],
		-2: [0, 0, 0, 0],
		-1: [0, 0, 0, 0],
		 0: [0, 0, 0, 0],
		 1: [0, 0, 0, 0],
		 2: [0, 0, 0, 0],
		 3: [0, 0, 0, 0],
	},
	"3": {
		-3: [0, 0, 0, 0],
		-2: [0, 0, 0, 0],
		-1: [0, 0, 0, 0],
		 0: [0, 0, 0, 0],
		 1: [0, 0, 0, 0],
		 2: [0, 0, 0, 0],
		 3: [0, 0, 0, 0],
	},
	"4": {
		-3: [0, 0, 0, 0],
		-2: [0, 0, 0, 0],
		-1: [0, 0, 0, 0],
		 0: [0, 0, 0, 0],
		 1: [0, 0, 0, 0],
		 2: [0, 0, 0, 0],
		 3: [0, 0, 0, 0],
	},
	"5": {
		-3: [0, 0, 0, 0],
		-2: [0, 0, 0, 0],
		-1: [0, 0, 0, 0],
		 0: [0, 0, 0, 0],
		 1: [0, 0, 0, 0],
		 2: [0, 0, 0, 0],
		 3: [0, 0, 0, 0],
	},
	"6": {
		-3: [0, 0, 0, 0],
		-2: [0, 0, 0, 0],
		-1: [0, 0, 0, 0],
		 0: [0, 0, 0, 0],
		 1: [0, 0, 0, 0],
		 2: [0, 0, 0, 0],
		 3: [0, 0, 0, 0],
	},
	"7": {
		-3: [0, 0, 0, 0],
		-2: [0, 0, 0, 0],
		-1: [0, 0, 0, 0],
		 0: [0, 0, 0, 0],
		 1: [0, 0, 0, 0],
		 2: [0, 0, 0, 0],
		 3: [0, 0, 0, 0],
	},
	"8": {
		-3: [0, 0, 0, 0],
		-2: [0, 0, 0, 0],
		-1: [0, 0, 0, 0],
		 0: [0, 0, 0, 0],
		 1: [0, 0, 0, 0],
		 2: [0, 0, 0, 0],
		 3: [0, 0, 0, 0],
	},
	"9": {
		-3: [0, 0, 0, 0],
		-2: [0, 0, 0, 0],
		-1: [0, 0, 0, 0],
		 0: [0, 0, 0, 0],
		 1: [0, 0, 0, 0],
		 2: [0, 0, 0, 0],
		 3: [0, 0, 0, 0],
	},
}
when i shorten the declaration, it works as expected:

Code: Select all

;works
Matrix := {
	"0": {
		-3: [0, 0, 0, 0],
		-2: [0, 0, 0, 0],
		-1: [0, 0, 0, 0],
		 0: [0, 0, 0, 0],
		 1: [0, 0, 0, 0],
		 2: [0, 0, 0, 0],
		 3: [0, 0, 0, 0],
	},
	"1": {
		-3: [0, 0, 0, 0],
		-2: [0, 0, 0, 0],
		-1: [0, 0, 0, 0],
		 0: [0, 0, 0, 0],
		 1: [0, 0, 0, 0],
		 2: [0, 0, 0, 0],
		 3: [0, 0, 0, 0],
	},
	"2": {
		-3: [0, 0, 0, 0],
		-2: [0, 0, 0, 0],
		-1: [0, 0, 0, 0],
		 0: [0, 0, 0, 0],
		 1: [0, 0, 0, 0],
		 2: [0, 0, 0, 0],
		 3: [0, 0, 0, 0],
	},
	"3": {
		-3: [0, 0, 0, 0],
		-2: [0, 0, 0, 0],
		-1: [0, 0, 0, 0],
		 0: [0, 0, 0, 0],
		 1: [0, 0, 0, 0],
		 2: [0, 0, 0, 0],
		 3: [0, 0, 0, 0],
	},
	"4": {
		-3: [0, 0, 0, 0],
		-2: [0, 0, 0, 0],
		-1: [0, 0, 0, 0],
		 0: [0, 0, 0, 0],
		 1: [0, 0, 0, 0],
		 2: [0, 0, 0, 0],
		 3: [0, 0, 0, 0],
	},
}
so what exactly does complexity or length refer to in this instance? is it a limit on the number of objects, character length, levels of nesting?
lexikos
Posts: 7086
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: [v2] Nested object declaration -> "Expression too complex"?

29 Jul 2018, 21:26

It can refer to one of two things:
  • Maximum 512 tokens - each operator symbol or literal value is a token. e.g. {"0": {}} is 6 tokens.
  • Maximum "derefs" (I don't remember what the limit is). Originally "derefs" were just variable and function references, but v2 does more processing at that stage (to support expression nesting inside % %, fat arrow functions, and possibly other things), so is more likely to reach the limit. I forget whether I came up with a better name for it than "deref". On the other hand, the limit might be 512, in which case hitting this limit means the max token limit would be exceeded anyway.
IIRC, I already have code lifting these limits, but haven't released it yet because lifting these limits means other limits become an issue:
  • Maximum 255 parameters in a function call.
  • Maximum ~64k characters per "combined line" (there is only one in your example).
I intend to remove these limits as well.
swagfag
Posts: 4034
Joined: 11 Jan 2017, 17:59

Re: [v2] Nested object declaration -> "Expression too complex"?

29 Jul 2018, 22:53

awesome, thanks for the clarification

Return to “AutoHotkey v2 Development”

Who is online

Users browsing this forum: No registered users and 4 guests