def find_alias_target(ast):
	""" If "ast" is an alias type, return its target.
	If "ast" is a type instance, go to the constructing type first.
	"""
	try_again = True
	while try_again:
		try_again = False

		if ast.name == 'type_instance':
			ast = ast.the('target').the('type')
			try_again = True

		while ast.name == 'type' and ast.the('customised'):
			ast = ast.the('customised').children[0]
			try_again = True

		while ast.name == 'type' and ast.get_attribute('meta_type') == ['alias']:
			ast = ast.the("target").children[0]
			try_again = True
	
	return ast