3

I just started looking into programming language design and came across the term intrinsic but could not find any good definition of this anywhere. I hope that someone here can help me with a good definition to broaden my understanding.

The description of the word in the Cambridge dictionary says:
Intrinsic (adjective)
"being an extremely important and basic characteristic of a person or thing"

There is also an intrinsic function which I think relates to mapping to assembler codes in the codegen phase, i.e. the back end of of a compiler.

In particular I want to understand the word in the context of the LLVM internal representation described in the LLVM Language Reference Manual.

Damian
  • 141
  • 5

2 Answers2

4

The term "intrinsic" does not have any special widely-used meaning in programming language design. In fact, I don't really have come across this term at all in relation to language design, but if it were to be used, then it would be either used with its standard English meaning, or with a special meaning defined by that particular programming language community.

The term "intrinsic function" is used by some compilers. This usage is also closely related to the standard English meaning. Intrinsic functions (or intrinsics, builtin functions, builtins, native functions, magic functions) are functions that get some sort of special treatment by the compiler. I.e. while user code can use them as if they were normal functions just like any other function, they will not be compiled like other functions. Rather, the compiler will use its intimate knowledge of what the function is supposed to do to (for example) replace it with special code optimized for the target platform.

This latter usage seems to be the one in the document you linked. Quoting from that same document (bold emphasis mine):

Intrinsic Global Variables

LLVM has a number of “magic” global variables that contain data that affect code generation or other IR semantics. […]

Intrinsic Functions

LLVM supports the notion of an “intrinsic function”. These functions have well known names and semantics and are required to follow certain restrictions. Overall, these intrinsics represent an extension mechanism for the LLVM language that does not require changing all of the transformations in LLVM when adding to the language (or the bitcode reader/writer, the parser, etc…).

[…] Intrinsic functions must always be external functions: you cannot define the body of intrinsic functions. […]

So, in terms of LLVM: an intrinsic function is a function that has no body (and thus no implementation, it doesn't need an implementation because it is treated specially by the compiler), has a special name, and is treated specially by the compiler.

An intrinsic global variable is a global variable that has the side-effect of affecting code generation or semantics.

Jörg W Mittag
  • 103,514
  • I suppose it could edge into language design if the language was defined by a canonical compiler that had intrinsics – Caleth Jan 10 '19 at 10:36
  • Also, in this particular example, the language in question is the internal representation of a compiler, so … – Jörg W Mittag Jan 10 '19 at 10:52
  • To me, an intrinsic function is one built-in to the language, like sqrt(). They are a fundamental part of the language. – shawnhcorey Feb 02 '19 at 15:56
  • To me, an intrinsic function is one built-in to the language, like sqrt(). They are a fundamental part of the language. – shawnhcorey Feb 02 '19 at 15:56
  • @shawnhcorey: In which language is sqrt() built into the language? E.g. in Ruby, Math::sqrt is part of the core library, not the language. In ECMAScript, Math.sqrt() is part of the standard library, not the language. In C, sqrt() is part of the <math.h> standard library, not the language. In Java, sqrt() is part of the JRE, not the language. In C♯, Visual Basic.NET, and F♯, sqrt is part of the BCL. In PHP, sqrt is part of the standard library. In Smalltalk, sqrt is part of the standard library. – Jörg W Mittag Feb 03 '19 at 01:59
  • @JörgWMittag Perl. https://perldoc.perl.org/functions/sqrt.html – shawnhcorey Feb 03 '19 at 12:26
0

Intrinsic

Something that is intrinsic is something known about a thing which does not need explanation or reason to define it. The intrinsic thing just is.

  • boa constrictors are intrinsically non-venomous
  • Red is intrinsically a colour.
  • 20 nano metres is intrinsically a spatial measurement.

These things do not require you to rely on anything outside of the thing itself to know. Unfortunately knowing does imply a lot of knowledge already, so roughly breaking it down:

  1. there is the real thing itself,
  2. the perception of the thing,
  3. and the representation of the thing in symbolic form.

A thing that is real does not require you to interpret it. If you weren't there it still would have that intrinsic quality.

An intrinsic thing that is perceptual is only known to that perception. A person who is Red/Green colour blind has no notion of Red, it is not a quality that is intrinsic to anything they perceive.

Something that is symbolically intrinsic is known because it is part of the symbols definition. A Bachelor for example is by definition an unmarried man. Unfortunately some symbolic representations are a little weird about what is intrinsic, take Boolean Logic. It requires you to understand a few definitions but you can pick:

  • true, false, and nand
  • true, false, and nor
  • true, not true, and, or, and not

Which ever definition you take, the rest of Boolean logic is well defined.

Extrinsic

Something that is extrinsic does not actually require that you know about the thing, but about how that thing relates to other things. A red/green colour blind person could relate the light frequency reflected by an object to identify red extrinsically. Similarly accepting logical axioms for true, false, and nand allows you to extrinsically understand or in boolean logic.

Anything that is extrinsic can be explained by connecting several intrinsic observations. This is the basis of pattern matching such as in a RegEx, given the intrinsic observation of characters (they just are), find a specific organisation of those characters.

Formal Language

So in a formal language an extrinsic part can be explained by some composition of intrinsic parts. While an intrinsic part must simply be known.

Some parts of the language could be both extrinsic, or intrinsic and what they are will depend on whether the reader of the language (usually the compiler/interpreter) intrinsically understands that part, or must derive understanding for that part through a composition of intrinsics.

What this means is that a compiler or interpreter must know in advance how to write instructions for, or how to act out some intrinsic part of the language. Of course a decision must be made as to what is intrinsic.

Sometimes the language specification declares everything (or more than needs to be) to be intrinsic. What this means is that anyone writing in this language should presume that anyone reading this will understand all of the definitions without explanation. Regardless of how they are actually known to the interpreter/compiler those definitions won't be treated like the definitions found in a written document. Usually one of those differences is that they cannot be redefined in a written document.

Kain0_0
  • 16,154